Class LangUtils

java.lang.Object
overit.geocallapp.utilities.lang.LangUtils

public class LangUtils extends Object
Utility class providing comprehensive language and localization management operations.
Since:
1.0
  • Field Details

  • Method Details

    • getFieldByLanguage

      public static String getFieldByLanguage(String language, String fieldName)
      Returns the translated field name for the specified language.
      Parameters:
      language - the target language name for translation
      fieldName - the original field name to translate
      Returns:
      the translated field name, or null if no translation is found
    • getTranslatedField

      public static String getTranslatedField(String field)
      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 the Identity context. 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

      public static String getFieldFromDictionary(String language, String fieldName)
      Retrieves the translated field name from the language dictionary using Teacher.
      Parameters:
      language - the target language name for translation
      fieldName - 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

      public static String getFieldFromDictionary(Teacher teacher, String fieldName)
      Retrieves the translated field name using a specific Teacher instance.
      Parameters:
      teacher - the Teacher instance 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

      public static String getFieldFromIdentity(String language, String fieldName)
      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 the Lang configuration in the current Identity.
      Parameters:
      language - the target language name
      fieldName - 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 process
      languageFieldValues - the map containing field values for different languages
      addDefaultFieldValuePrefix - true to add language prefix to default values, false otherwise
    • addMissingTranslations

      public static void addMissingTranslations(String fieldName, Map<String,Object> languageFieldValues)
      Adds missing translations for all configured languages to the field values map.
      Parameters:
      fieldName - the base field name to process
      languageFieldValues - 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 language
      languageFieldValues - the map containing field values for different languages
      defaultFieldValue - 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 for
      languageFieldValues - the map containing field values for different languages
      addDefaultFieldValuePrefix - true to add language prefix to default values, false otherwise
      Returns:
      the default field value with language prefix, or null if not found
    • getDefaultFieldValue

      public static String getDefaultFieldValue(String fieldName, Map<String,Object> languageFieldValues)
      Return the default field value.
      Parameters:
      fieldName - the field name
      languageFieldValues - the translated field name
      Returns:
      the default field
    • getDefaultFieldValuePrefix

      public static String getDefaultFieldValuePrefix()
      Return the default field prefix.
      Returns:
      the default field prefix
    • isMultilanguageField

      public static Boolean isMultilanguageField(Lang lang, String name)
      Checks whether the field is multilanguage.
      Parameters:
      lang - the Lang instance to use for translation checking
      name - 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

      public static boolean hasTranslation(String fieldName, Teacher teacher)
      Checks whether the given field has the required translation.
      Parameters:
      fieldName - the field name to check for translation availability
      teacher - the Teacher instance to use for translation lookup
      Returns:
      true if the field has a valid translation available, false otherwise
    • completeMultilanguageFields

      public static <T extends DynO> void completeMultilanguageFields(T businessObject)
      Check for each LocalizedString field of the input object if it has a LocalizedString.LocalizedItem for each system language. If not, add the missing LocalizedString.LocalizedItem entries for all configured languages.
      Type Parameters:
      T - the type of business object extending DynO
      Parameters:
      businessObject - the DynO business object to process for multilanguage field completion
    • addMissingTranslations

      public static void addMissingTranslations(LocalizedString localizedString)
      Check if the LocalizedString input have a LocalizedString.LocalizedItem for each system language. If not, add these new entries duplicating the current language value.
      Parameters:
      localizedString - the LocalizedString object to complete with missing language entries (can be null)
    • checkEmptyLocalizedString

      public static boolean checkEmptyLocalizedString(LocalizedString localizedString, boolean isNullOrEmptyValid)
      Check if the LocalizedString is correctly filled in.
      Parameters:
      localizedString - the LocalizedString object 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

      public static LocalizedString getLocalizedStringForCurrentLanguage(String description)
      Build a new LocalizedString object assigning the input description to the current language.
      Parameters:
      description - the text description to assign to the current user's language
      Returns:
      a new LocalizedString containing the description for the current language
    • getLocalizedStringForAllLanguages

      public static LocalizedString getLocalizedStringForAllLanguages(String text, Object[] parameters)
      Builds a new LocalizedString object with the given text translated in all languages and formatted with given parameters.
      Parameters:
      text - the base text to translate across all configured languages
      parameters - the formatting parameters to apply to translated text (can be null)
      Returns:
      a new LocalizedString containing translations for all configured languages
    • translate

      public static String translate(Identity id, String toTranslate)
      Translates the given string using the language settings from the provided Identity.
      Parameters:
      id - the Identity instance to retrieve the language configuration and Teacher
      toTranslate - the text string to be translated
      Returns:
      the translated string, or the original string if no translation is available