Inherited by ERXItalianLocalizer, and ERXNonPluralFormLocalizer.

Monitors a set of files in all loaded frameworks and returns a string given a key for a language. These types of keys are acceptable in the monitored files:
"this is a test" = "some test";
"unittest.key.path.as.string" = "some test";
"unittest" = {
"key" = {
"path" = {
"as" = {
"dict"="some test";
};
};
};
};
Note that if you only call for unittest, you'll get a dictionary not a string. So you can localize more complex objects than strings.
If you set the base class of your session to ERXSession, you can then use this code in your components:
valueForKeyPath("session.localizer.this is a test")
valueForKeyPath("session.localizer.unittest.key.path.as.string")
valueForKeyPath("session.localizer.unittest.key.path.as.dict")
For sessionless Apps, you must use another method to get at the requested language and then call the localizer via:
ERXLocalizer l = ERXLocalizer.localizerForLanguages(languagesThisUserCanHandle) or
ERXLocalizer l = ERXLocalizer.localizerForLanguage("German")
These are the defaults can be set (listed with their current defaults):
er.extensions.ERXLocalizer.defaultLanguage=English
er.extensions.ERXLocalizer.fileNamesToWatch=("Localizable.strings","ValidationTemplate.strings")
er.extensions.ERXLocalizer.availableLanguages=(English,German)
er.extensions.ERXLocalizer.frameworkSearchPath=(app,ERDirectToWeb,ERExtensions)
There are also methods that pluralize using normal english pluralizing rules (y->ies, x -> xes etc). You can provide your own plural strings by using a dict entry:
localizerExceptions = {
"Table.0" = "Table";
"Table" = "Tables";
...
};
in your Localizable.strings. Table.0 meaning no "Table", Table.1 one table and Table any other number. Note: unlike all other keys, you need to give the translated value ("Tisch" for "Table" in German) as the key, not the untranslated one. This is because this method is mainly called via d2wContext.displayNameForProperty which is already localized.
| ERXLocalizer | ( | String | aLanguage | ) |
| void addEntriesToCache | ( | NSDictionary | dict | ) | [protected] |
| void addToCreatedKeys | ( | Object | value, | |
| String | key | |||
| ) | [protected] |
Apply the set of rules in the given Map to the input String and return a modified string that matches the case of the input string. For instance, if the input string is "Person" and the rules are _plurifyRules, then this would return "People".
| str | the input string | |
| rules | the rules to apply |
| static NSArray<String> availableLanguages | ( | ) | [static] |
| NSDictionary cache | ( | ) |
| NSDictionary createdKeys | ( | ) |
| static ERXLocalizer createLocalizerForLanguage | ( | String | language, | |
| boolean | pluralForm | |||
| ) | [static, protected] |
Creates a localizer for a given language and with an indication if the language supports plural forms. To provide your own subclass of an ERXLocalizer you can set the system property er.extensions.ERXLocalizer.pluralFormClassName or er.extensions.ERXLocalizer.nonPluralFormClassName.
| language | name to construct the localizer for | |
| pluralForm | denotes if the language supports the plural form |
| static ERXLocalizer currentLocalizer | ( | ) | [static] |
Returns the current localizer for the current thread. Note that the localizer for a given session is pushed onto the thread when a session awakes and is nulled out when a session sleeps. In case there is no localizer set, it tries to pull it from the current WOContext or the default language.
| static String defaultLanguage | ( | ) | [static] |
Returns the default language (English) or the contents of the er.extensions.ERXLocalizer.defaultLanguage property.
| static ERXLocalizer defaultLocalizer | ( | ) | [static] |
Gets the localizer for the default language.
| Map defaultPlurifyRules | ( | ) | [protected] |
Returns the default plurify rules for this language. The default implementation is English and ported from the plurify code in Ruby on Rails. The returned Map should have regex Pattern objects as keys mapping to the replacement String to apply to that pattern.
| Map defaultSingularifyRules | ( | ) | [protected] |
Returns the default singularify rules for this language. The default implementation is English and ported from the singularize code in Ruby on Rails. The returned Map should have regex Pattern objects as keys mapping to the replacement String to apply to that pattern.
| void dumpCreatedKeys | ( | ) |
| static ERXLocalizer englishLocalizer | ( | ) | [static] |
| static boolean fallbackToDefaultLanguage | ( | ) | [static] |
| static NSArray fileNamesToWatch | ( | ) | [static] |
| static NSArray<String> frameworkSearchPath | ( | ) | [static] |
| static void initialize | ( | ) | [static] |
| static boolean isLocalizationEnabled | ( | ) | [static] |
| String languageCode | ( | ) |
| void load | ( | ) |
| Locale locale | ( | ) |
| Format localizedDateFormatForKey | ( | String | formatString | ) |
Returns a localized date formatter for the given key.
| formatString |
Returns a localized string for the given prefix and keyPath, inserting it "prefix.keyPath" = "Key Path"; Also tries to find "Key Path"
| prefix | ||
| key |
| Format localizedNumberFormatForKey | ( | String | formatString | ) |
Returns a localized number formatter for the given key. Also, can localize units to, just define in your Localizable.strings a suitable key, with the appropriate pattern.
| formatString |
| Object localizedValueForKey | ( | String | key | ) |
Returns the localized value for a key. An @ keypath such as session.localizer.@locale.getLanguage indicates that the methods on ERXLocalizer itself should be called instead of searching the strings file for a '.getLanguage' key.
| key | the keyPath string |
| Object localizedValueForKeyWithDefault | ( | String | key | ) |
| static ERXLocalizer localizerForLanguage | ( | String | language | ) | [static] |
| static ERXLocalizer localizerForLanguages | ( | NSArray | languages | ) | [static] |
Gets the best localizer for a set of languages.
| languages |
| static ERXLocalizer localizerForRequest | ( | WORequest | request | ) | [static] |
Reimplemented in ERXItalianLocalizer.
| Map plurifyRules | ( | ) | [protected] |
Returns the plurify rules for the current language. This first checks for a property of the form:
er.extensions.ERXLocalizer.en.plurifyRules=(.*)person$=$1people:(.*)man$=$1men
which is
er.extensions.ERXLocalizer.en.plurifyRules=pattern1=replacement1:pattern2=replacement2:etc
In the absence of a rule set for a particular language, the default rules are English and ported from the pluralizer in Rails.
| NSDictionary readPropertyListFromFileInFramework | ( | String | fileName, | |
| String | framework, | |||
| NSArray | languages | |||
| ) | [protected] |
| static void resetCache | ( | ) | [static] |
Resets the localizer cache. If WOCaching is enabled then after being reinitialize all of the localizers will be reloaded.
| static void setAvailableLanguages | ( | NSArray< String > | value | ) | [static] |
| void setCacheValueForKey | ( | Object | value, | |
| String | key | |||
| ) | [protected] |
| static void setCurrentLocalizer | ( | ERXLocalizer | currentLocalizer | ) | [static] |
Sets a localizer for the current thread. This is accomplished by using the object ERXThreadStorage
| currentLocalizer | to set in thread storage for the current thread. |
| static void setDefaultLanguage | ( | String | value | ) | [static] |
Sets the default language.
| value |
| static void setFileNamesToWatch | ( | NSArray | value | ) | [static] |
| static void setFrameworkSearchPath | ( | NSArray | value | ) | [static] |
| static void setIsLocalizationEnabled | ( | boolean | value | ) | [static] |
| void setLocale | ( | Locale | value | ) |
| void setLocalizedDateFormatForKey | ( | NSTimestampFormatter | formatter, | |
| String | pattern | |||
| ) |
| formatter | ||
| pattern |
| void setLocalizedNumberFormatForKey | ( | Format | formatter, | |
| String | pattern | |||
| ) |
| formatter | ||
| pattern |
| static void setLocalizerForLanguage | ( | ERXLocalizer | l, | |
| String | language | |||
| ) | [static] |
Returns a singularified string
| value | the value to singularify |
| Map singularifyRules | ( | ) | [protected] |
Returns the singularify rules for the current language. This first checks for a property of the form:
er.extensions.ERXLocalizer.en.singularifyRules=(.*)person$=$1people:(.*)man$=$1men
which is
er.extensions.ERXLocalizer.en.singularifyRules=pattern1=replacement1:pattern2=replacement2:etc
In the absence of a rule set for a particular language, the default rules are English and ported from the singularizer in Rails.
| void takeValueForKey | ( | Object | value, | |
| String | key | |||
| ) |
| void takeValueForKeyPath | ( | Object | value, | |
| String | key | |||
| ) |
| String toString | ( | ) |
Reimplemented in ERXNonPluralFormLocalizer.
| static boolean useLocalizedFormatters | ( | ) | [static] |
| Object valueForKey | ( | String | key | ) |
Cover method that calls localizedStringForKey.
| key | to resolve a localized varient of |
| Object valueForKeyPath | ( | String | key | ) |
Hashtable _dateFormatters = new Hashtable() [protected] |
Boolean _fallbackToDefaultLanguage [static, private] |
NSArray _languagesWithoutPluralForm = new NSArray(new Object[] { "Japanese" }) [static, private] |
final char _localizerMethodIndicatorCharacter = '@' [static, private] |
Hashtable _numberFormatters = new Hashtable() [protected] |
Map _plurifyRules [private] |
Map _singularifyRules [private] |
Boolean _useLocalizedFormatters [static, private] |
NSArray<String> availableLanguages [static, package] |
NSMutableDictionary cache [protected] |
NSMutableDictionary createdKeys [private] |
final Logger createdKeysLog = Logger.getLogger(ERXLocalizer.class.getName() + ".createdKeys") [static, protected] |
String defaultLanguage [static, package] |
NSArray<String> fileNamesToWatch [static, package] |
NSArray<String> frameworkSearchPath [static, package] |
boolean isInitialized = false [static, private] |
boolean isLocalizationEnabled = true [static, private] |
final String KEY_LOCALIZER_EXCEPTIONS = "localizerExceptions" [static] |
Locale locale [protected] |
final String LocalizationDidResetNotification = "LocalizationDidReset" [static] |
NSMutableDictionary localizers = new NSMutableDictionary() [static, package] |
final Logger log = Logger.getLogger(ERXLocalizer.class) [static, protected] |
Reimplemented in ERXItalianLocalizer, and ERXNonPluralFormLocalizer.
NSMutableArray monitoredFiles = new NSMutableArray() [static, private] |
1.5.8