Class I18n
java.lang.Object
io.leandev.appfuse.nls.I18n
Internationalization (I18n) utility class for handling translations and locale-specific formatting. This class provides methods for translating text, formatting dates, numbers, and other locale-specific operations.
Thread-safe implementation using ConcurrentHashMap for caching dictionaries. Supports fallback mechanisms for missing translations and locale hierarchies.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription取得目前語系的日期格式。 若語系未定義格式,則回傳預設格式 "yyyy-MM-dd"。datePattern(String defaultDatePattern) 取得目前語系的日期格式。 若語系未定義格式,則回傳指定的預設格式。datePattern(Locale locale) 取得指定語系的日期格式。 若語系未定義格式,則回傳預設格式 "yyyy-MM-dd"。datePattern(Locale locale, String defaultDatePattern) 取得指定語系的日期格式。 若語系未定義格式,則回傳指定的預設格式。取得目前語系的日期時間格式。 若語系未定義格式,則回傳預設格式 "yyyy-MM-dd HH:mm:ss"。datetimePattern(String defaultDatetimePattern) 取得目前語系的日期時間格式。 若語系未定義格式,則回傳指定的預設格式。datetimePattern(Locale locale) 取得指定語系的日期時間格式。 若語系未定義格式,則回傳預設格式 "yyyy-MM-dd HH:mm:ss"。datetimePattern(Locale locale, String defaultDatetimePattern) floatPattern(String defaultPattern) floatPattern(Locale locale) floatPattern(Locale locale, String defaultPattern) fontFamily(String defaultFontFamily) fontFamily(Locale locale) fontFamily(Locale locale, String defaultFontFamily) static I18nintegerPattern(String defaultPattern) integerPattern(Locale locale) integerPattern(Locale locale, String defaultPattern) Interprets a translation key within a specific namespace and locale.locale()moneyPattern(String defaultPattern) moneyPattern(Locale locale) moneyPattern(Locale locale, String defaultPattern) numberPattern(String defaultPattern) numberPattern(Locale locale) numberPattern(Locale locale, String defaultPattern) voidSets the locale for this I18n instance.timePattern(String defaultDatePattern) timePattern(Locale locale) timePattern(Locale locale, String defaultDatePattern) Translates the given text using the instance's default locale.
-
Constructor Details
-
I18n
public I18n()Default constructor that uses the system default locale. -
I18n
Constructor with a specific locale.- Parameters:
locale- the locale to use, if null defaults to system default
-
-
Method Details
-
getInstance
-
setLocale
Sets the locale for this I18n instance.- Parameters:
locale- the locale to set, if null defaults to system default
-
locale
-
translate
-
translate
-
translate
-
translate
-
translate
-
interpret
Interprets a translation key within a specific namespace and locale. Provides multi-level fallback mechanism:
- Try country-specific locale (e.g., zh-TW)
- Try language-only locale (e.g., zh)
- Try English (en) as final fallback
- Parameters:
text- the translation keynamespace- the namespace (e.g., "term", "message", "app")locale- the target locale, if null defaults to system default- Returns:
- the translated text, or null if no translation found
-
term
-
term
-
message
-
message
-
datetimePattern
取得目前語系的日期時間格式。 若語系未定義格式,則回傳預設格式 "yyyy-MM-dd HH:mm:ss"。- Returns:
- 日期時間格式字串
-
datetimePattern
-
datetimePattern
-
datetimePattern
-
datePattern
-
datePattern
-
datePattern
-
datePattern
-
timePattern
-
timePattern
-
timePattern
-
timePattern
-
numberPattern
-
numberPattern
-
numberPattern
-
numberPattern
-
moneyPattern
-
moneyPattern
-
moneyPattern
-
moneyPattern
-
integerPattern
-
integerPattern
-
integerPattern
-
integerPattern
-
floatPattern
-
floatPattern
-
floatPattern
-
floatPattern
-
fontFamily
-
fontFamily
-
fontFamily
-
fontFamily
-
get
-
get
-