Package overit.geocallapp.utilities.lang
Class LangUtils
java.lang.Object
overit.geocallapp.utilities.lang.LangUtils
Utility class providing comprehensive language and localization management operations.
- Since:
- 1.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddMissingTranslation(String fieldForLanguage, Map<String, Object> languageFieldValues, String defaultFieldValue) Adds a missing translation for the specified field in the field values map.static voidaddMissingTranslations(String fieldName, Map<String, Object> languageFieldValues) Adds missing translations for all configured languages to the field values map.static voidaddMissingTranslations(String fieldName, Map<String, Object> languageFieldValues, boolean addDefaultFieldValuePrefix) Adds missing translations for all configured languages to the field values map.static voidaddMissingTranslations(LocalizedString localizedString) Check if theLocalizedStringinput have aLocalizedString.LocalizedItemfor each system language.static booleancheckEmptyLocalizedString(LocalizedString localizedString, boolean isNullOrEmptyValid) Check if theLocalizedStringis correctly filled in.static <T extends DynO>
voidcompleteMultilanguageFields(T businessObject) Check for eachLocalizedStringfield of the input object if it has aLocalizedString.LocalizedItemfor each system language.static StringgetDefaultFieldValue(String fieldName, Map<String, Object> languageFieldValues) Return the default field value.static StringgetDefaultFieldValue(String fieldName, Map<String, Object> languageFieldValues, boolean addDefaultFieldValuePrefix) Returns the default field value for the given field name using the current language.static StringReturn the default field prefix.static StringgetFieldByLanguage(String language, String fieldName) Returns the translated field name for the specified language.static StringgetFieldFromDictionary(String language, String fieldName) Retrieves the translated field name from the language dictionary usingTeacher.static StringgetFieldFromDictionary(Teacher teacher, String fieldName) Retrieves the translated field name using a specificTeacherinstance.static StringgetFieldFromIdentity(String language, String fieldName) Constructs a language-specific field name by appending the table suffix.static LocalizedStringgetLocalizedStringForAllLanguages(String text, Object[] parameters) Builds a newLocalizedStringobject with the given text translated in all languages and formatted with given parameters.static LocalizedStringgetLocalizedStringForCurrentLanguage(String description) Build a newLocalizedStringobject assigning the input description to the current language.static StringgetTranslatedField(String field) Retrieves the translated field name for the current user's language.static booleanhasTranslation(String fieldName, Teacher teacher) Checks whether the given field has the required translation.static BooleanisMultilanguageField(Lang lang, String name) Checks whether the field is multilanguage.static StringTranslates the given string using the language settings from the providedIdentity.
-
Field Details
-
UI_TEACHER_SIZE
public static final int UI_TEACHER_SIZE- See Also:
-
-
Method Details
-
getFieldByLanguage
Returns the translated field name for the specified language.- Parameters:
language- the target language name for translationfieldName- the original field name to translate- Returns:
- the translated field name, or null if no translation is found
-
getTranslatedField
Retrieves the translated field name for the current user's language. This method attempts to translate the given field name to the current user's language using theIdentitycontext. If no translation is found, it returns the original field name as a fallback.- Parameters:
field- the original field name to translate- Returns:
- the translated field name for the user's language, or the original field name if no translation exists
-
getFieldFromDictionary
Retrieves the translated field name from the language dictionary usingTeacher.- Parameters:
language- the target language name for translationfieldName- the original field name to translate- Returns:
- the translated field name, or null if no translation is found or if the translation equals the original
-
getFieldFromDictionary
Retrieves the translated field name using a specificTeacherinstance.- Parameters:
teacher- theTeacherinstance for a specific language (can be null)fieldName- the original field name to translate- Returns:
- the translated field name, or the original field name if teacher is null or no translation exists
-
getFieldFromIdentity
Constructs a language-specific field name by appending the table suffix. This method creates a field name for database operations by appending the language-specific table suffix to the original field name. The suffix is retrieved from theLangconfiguration in the currentIdentity.- Parameters:
language- the target language namefieldName- the base field name- Returns:
- the field name with language-specific table suffix appended, or null if language is not found
-
addMissingTranslations
public static void addMissingTranslations(String fieldName, Map<String, Object> languageFieldValues, boolean addDefaultFieldValuePrefix) Adds missing translations for all configured languages to the field values map.- Parameters:
fieldName- the base field name to processlanguageFieldValues- the map containing field values for different languagesaddDefaultFieldValuePrefix- true to add language prefix to default values, false otherwise
-
addMissingTranslations
Adds missing translations for all configured languages to the field values map.- Parameters:
fieldName- the base field name to processlanguageFieldValues- the map containing field values for different languages
-
addMissingTranslation
public static void addMissingTranslation(String fieldForLanguage, Map<String, Object> languageFieldValues, String defaultFieldValue) Adds a missing translation for the specified field in the field values map.- Parameters:
fieldForLanguage- the field name for the specific languagelanguageFieldValues- the map containing field values for different languagesdefaultFieldValue- the default value to use for the missing translation
-
getDefaultFieldValue
public static String getDefaultFieldValue(String fieldName, Map<String, Object> languageFieldValues, boolean addDefaultFieldValuePrefix) Returns the default field value for the given field name using the current language.- Parameters:
fieldName- the field name to retrieve the default value forlanguageFieldValues- the map containing field values for different languagesaddDefaultFieldValuePrefix- true to add language prefix to default values, false otherwise- Returns:
- the default field value with language prefix, or null if not found
-
getDefaultFieldValue
Return the default field value.- Parameters:
fieldName- the field namelanguageFieldValues- the translated field name- Returns:
- the default field
-
getDefaultFieldValuePrefix
Return the default field prefix.- Returns:
- the default field prefix
-
isMultilanguageField
Checks whether the field is multilanguage.- Parameters:
lang- theLanginstance to use for translation checkingname- the field name to check for multilanguage support- Returns:
- true if the field has different translations available, false if it uses the same name across languages
-
hasTranslation
Checks whether the given field has the required translation.- Parameters:
fieldName- the field name to check for translation availabilityteacher- theTeacherinstance to use for translation lookup- Returns:
- true if the field has a valid translation available, false otherwise
-
completeMultilanguageFields
Check for eachLocalizedStringfield of the input object if it has aLocalizedString.LocalizedItemfor each system language. If not, add the missingLocalizedString.LocalizedItementries for all configured languages. -
addMissingTranslations
Check if theLocalizedStringinput have aLocalizedString.LocalizedItemfor each system language. If not, add these new entries duplicating the current language value.- Parameters:
localizedString- theLocalizedStringobject to complete with missing language entries (can be null)
-
checkEmptyLocalizedString
public static boolean checkEmptyLocalizedString(LocalizedString localizedString, boolean isNullOrEmptyValid) Check if theLocalizedStringis correctly filled in.- Parameters:
localizedString- theLocalizedStringobject to validate (can be null)isNullOrEmptyValid- true for update operations (allows partial filling), false for insert operations (requires all languages)- Returns:
- true if the LocalizedString meets the validation criteria, false otherwise
-
getLocalizedStringForCurrentLanguage
Build a newLocalizedStringobject assigning the input description to the current language.- Parameters:
description- the text description to assign to the current user's language- Returns:
- a new
LocalizedStringcontaining the description for the current language
-
getLocalizedStringForAllLanguages
Builds a newLocalizedStringobject with the given text translated in all languages and formatted with given parameters.- Parameters:
text- the base text to translate across all configured languagesparameters- the formatting parameters to apply to translated text (can be null)- Returns:
- a new
LocalizedStringcontaining translations for all configured languages
-
translate
Translates the given string using the language settings from the providedIdentity.- Parameters:
id- theIdentityinstance to retrieve the language configuration and TeachertoTranslate- the text string to be translated- Returns:
- the translated string, or the original string if no translation is available
-