|
Project Wonder 5.0 | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecter.extensions.localization.ERXLocalizer
public class ERXLocalizer
Provides KVC access to localization. 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.
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.
Nested Class Summary | |
---|---|
static class |
ERXLocalizer.Observer
|
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
---|
com.webobjects.foundation.NSKeyValueCodingAdditions.DefaultImplementation, com.webobjects.foundation.NSKeyValueCodingAdditions.Utility |
Nested classes/interfaces inherited from interface com.webobjects.foundation.NSKeyValueCoding |
---|
com.webobjects.foundation.NSKeyValueCoding._BooleanFieldBinding, com.webobjects.foundation.NSKeyValueCoding._BooleanMethodBinding, com.webobjects.foundation.NSKeyValueCoding._FieldBinding, com.webobjects.foundation.NSKeyValueCoding._ForwardingBinding, com.webobjects.foundation.NSKeyValueCoding._KeyBinding, com.webobjects.foundation.NSKeyValueCoding._KeyBindingCreation, com.webobjects.foundation.NSKeyValueCoding._MethodBinding, com.webobjects.foundation.NSKeyValueCoding._NumberFieldBinding, com.webobjects.foundation.NSKeyValueCoding._NumberMethodBinding, com.webobjects.foundation.NSKeyValueCoding._ReflectionKeyBindingCreation, com.webobjects.foundation.NSKeyValueCoding.ErrorHandling, com.webobjects.foundation.NSKeyValueCoding.Null, com.webobjects.foundation.NSKeyValueCoding.UnknownKeyException, com.webobjects.foundation.NSKeyValueCoding.ValueAccessor |
Field Summary | |
---|---|
protected java.util.Hashtable |
_dateFormatters
|
protected java.util.Hashtable |
_numberFormatters
|
protected com.webobjects.foundation.NSMutableDictionary |
cache
|
protected static org.apache.log4j.Logger |
createdKeysLog
|
static java.lang.String |
KEY_LOCALIZER_EXCEPTIONS
|
protected java.lang.String |
language
|
protected java.util.Locale |
locale
|
static java.lang.String |
LocalizationDidResetNotification
|
protected static org.apache.log4j.Logger |
log
|
Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
---|
_CLASS, _KeyPathSeparatorChar, KeyPathSeparator |
Fields inherited from interface com.webobjects.foundation.NSKeyValueCoding |
---|
NullValue |
Constructor Summary | |
---|---|
ERXLocalizer(java.lang.String aLanguage)
|
Method Summary | |
---|---|
protected void |
addEntriesToCache(com.webobjects.foundation.NSDictionary dict)
|
protected void |
addToCreatedKeys(java.lang.Object value,
java.lang.String key)
|
protected java.lang.String |
applyRules(java.lang.String str,
java.util.Map rules)
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. |
static com.webobjects.foundation.NSArray<java.lang.String> |
availableLanguages()
|
com.webobjects.foundation.NSDictionary |
cache()
|
com.webobjects.foundation.NSDictionary |
createdKeys()
|
protected static ERXLocalizer |
createLocalizerForLanguage(java.lang.String language,
boolean pluralForm)
Creates a localizer for a given language and with an indication if the language supports plural forms. |
static ERXLocalizer |
currentLocalizer()
Returns the current localizer for the current thread. |
static java.lang.String |
defaultLanguage()
Returns the default language (English) or the contents of the er.extensions.ERXLocalizer.defaultLanguage property. |
static ERXLocalizer |
defaultLocalizer()
Gets the localizer for the default language. |
protected java.util.Map |
defaultPlurifyRules()
Returns the default plurify rules for this language. |
protected java.util.Map |
defaultSingularifyRules()
Returns the default singularify rules for this language. |
void |
dumpCreatedKeys()
|
static ERXLocalizer |
englishLocalizer()
|
static boolean |
fallbackToDefaultLanguage()
|
static com.webobjects.foundation.NSArray |
fileNamesToWatch()
|
static com.webobjects.foundation.NSArray<java.lang.String> |
frameworkSearchPath()
|
static void |
initialize()
|
static boolean |
isLocalizationEnabled()
|
java.lang.String |
language()
|
java.lang.String |
languageCode()
|
void |
load()
|
java.util.Locale |
locale()
|
java.text.Format |
localizedDateFormatForKey(java.lang.String formatString)
Returns a localized date formatter for the given key. |
java.lang.String |
localizedDisplayNameForKey(java.lang.String prefix,
java.lang.String key)
Returns a localized string for the given prefix and keyPath, inserting it "prefix.keyPath" = "Key Path"; Also tries to find "Key Path" |
java.text.Format |
localizedNumberFormatForKey(java.lang.String formatString)
Returns a localized number formatter for the given key. |
java.lang.String |
localizedStringForKey(java.lang.String key)
|
java.lang.String |
localizedStringForKeyWithDefault(java.lang.String key)
|
java.lang.String |
localizedTemplateStringForKeyWithObject(java.lang.String key,
java.lang.Object o1)
|
java.lang.String |
localizedTemplateStringForKeyWithObjectOtherObject(java.lang.String key,
java.lang.Object o1,
java.lang.Object o2)
|
java.lang.Object |
localizedValueForKey(java.lang.String key)
Returns the localized value for a key. |
java.lang.Object |
localizedValueForKeyWithDefault(java.lang.String key)
|
static ERXLocalizer |
localizerForLanguage(java.lang.String language)
|
static ERXLocalizer |
localizerForLanguages(com.webobjects.foundation.NSArray languages)
Gets the best localizer for a set of languages. |
static ERXLocalizer |
localizerForRequest(com.webobjects.appserver.WORequest request)
|
java.lang.String |
plurifiedString(java.lang.String name,
int count)
Returns a plurified string |
java.lang.String |
plurifiedStringWithTemplateForKey(java.lang.String key,
java.lang.String name,
int count,
java.lang.Object helper)
|
protected java.lang.String |
plurify(java.lang.String str,
int howMany)
|
protected java.util.Map |
plurifyRules()
Returns the plurify rules for the current language. |
protected com.webobjects.foundation.NSDictionary |
readPropertyListFromFileInFramework(java.lang.String fileName,
java.lang.String framework,
com.webobjects.foundation.NSArray languages)
|
static void |
resetCache()
Resets the localizer cache. |
static void |
setAvailableLanguages(com.webobjects.foundation.NSArray<java.lang.String> value)
|
protected void |
setCacheValueForKey(java.lang.Object value,
java.lang.String key)
|
static void |
setCurrentLocalizer(ERXLocalizer currentLocalizer)
Sets a localizer for the current thread. |
static void |
setDefaultLanguage(java.lang.String value)
Sets the default language. |
static void |
setFileNamesToWatch(com.webobjects.foundation.NSArray value)
|
static void |
setFrameworkSearchPath(com.webobjects.foundation.NSArray value)
|
static void |
setIsLocalizationEnabled(boolean value)
|
void |
setLocale(java.util.Locale value)
|
void |
setLocalizedDateFormatForKey(com.webobjects.foundation.NSTimestampFormatter formatter,
java.lang.String pattern)
|
void |
setLocalizedNumberFormatForKey(java.text.Format formatter,
java.lang.String pattern)
|
static void |
setLocalizerForLanguage(ERXLocalizer l,
java.lang.String language)
|
java.lang.String |
singularifiedString(java.lang.String value)
Returns a singularified string |
protected java.lang.String |
singularify(java.lang.String str)
|
protected java.util.Map |
singularifyRules()
Returns the singularify rules for the current language. |
void |
takeValueForKey(java.lang.Object value,
java.lang.String key)
|
void |
takeValueForKeyPath(java.lang.Object value,
java.lang.String key)
|
java.lang.String |
toString()
|
static boolean |
useLocalizedFormatters()
|
java.lang.Object |
valueForKey(java.lang.String key)
Cover method that calls localizedStringForKey . |
java.lang.Object |
valueForKeyPath(java.lang.String key)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String KEY_LOCALIZER_EXCEPTIONS
protected static final org.apache.log4j.Logger log
protected static final org.apache.log4j.Logger createdKeysLog
public static final java.lang.String LocalizationDidResetNotification
protected com.webobjects.foundation.NSMutableDictionary cache
protected java.util.Hashtable _dateFormatters
protected java.util.Hashtable _numberFormatters
protected java.lang.String language
protected java.util.Locale locale
Constructor Detail |
---|
public ERXLocalizer(java.lang.String aLanguage)
Method Detail |
---|
public static void initialize()
public static boolean isLocalizationEnabled()
public static void setIsLocalizationEnabled(boolean value)
public static ERXLocalizer currentLocalizer()
public static void setCurrentLocalizer(ERXLocalizer currentLocalizer)
ERXThreadStorage
currentLocalizer
- to set in thread storage for the current thread.public static ERXLocalizer defaultLocalizer()
public static ERXLocalizer englishLocalizer()
public static ERXLocalizer localizerForRequest(com.webobjects.appserver.WORequest request)
public static void resetCache()
protected void addToCreatedKeys(java.lang.Object value, java.lang.String key)
public static ERXLocalizer localizerForLanguages(com.webobjects.foundation.NSArray languages)
languages
- public static ERXLocalizer localizerForLanguage(java.lang.String language)
public static java.lang.String defaultLanguage()
er.extensions.ERXLocalizer.defaultLanguage
property.
public static void setDefaultLanguage(java.lang.String value)
value
- public static com.webobjects.foundation.NSArray fileNamesToWatch()
public static void setFileNamesToWatch(com.webobjects.foundation.NSArray value)
public static com.webobjects.foundation.NSArray<java.lang.String> availableLanguages()
public static void setAvailableLanguages(com.webobjects.foundation.NSArray<java.lang.String> value)
public static com.webobjects.foundation.NSArray<java.lang.String> frameworkSearchPath()
public static void setFrameworkSearchPath(com.webobjects.foundation.NSArray value)
protected static ERXLocalizer createLocalizerForLanguage(java.lang.String language, boolean pluralForm)
er.extensions.ERXLocalizer.pluralFormClassName
or
er.extensions.ERXLocalizer.nonPluralFormClassName
.
language
- name to construct the localizer forpluralForm
- denotes if the language supports the plural form
public static void setLocalizerForLanguage(ERXLocalizer l, java.lang.String language)
public com.webobjects.foundation.NSDictionary cache()
public void load()
protected java.util.Map plurifyRules()
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.
protected java.util.Map defaultPlurifyRules()
protected java.util.Map singularifyRules()
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.
protected java.util.Map defaultSingularifyRules()
protected void addEntriesToCache(com.webobjects.foundation.NSDictionary dict)
protected com.webobjects.foundation.NSDictionary readPropertyListFromFileInFramework(java.lang.String fileName, java.lang.String framework, com.webobjects.foundation.NSArray languages)
public java.lang.Object valueForKey(java.lang.String key)
localizedStringForKey
.
valueForKey
in interface com.webobjects.foundation.NSKeyValueCoding
key
- to resolve a localized varient of
protected void setCacheValueForKey(java.lang.Object value, java.lang.String key)
public java.lang.Object valueForKeyPath(java.lang.String key)
valueForKeyPath
in interface com.webobjects.foundation.NSKeyValueCodingAdditions
public void takeValueForKey(java.lang.Object value, java.lang.String key)
takeValueForKey
in interface com.webobjects.foundation.NSKeyValueCoding
public void takeValueForKeyPath(java.lang.Object value, java.lang.String key)
takeValueForKeyPath
in interface com.webobjects.foundation.NSKeyValueCodingAdditions
public java.lang.String language()
public com.webobjects.foundation.NSDictionary createdKeys()
public void dumpCreatedKeys()
public java.lang.Object localizedValueForKeyWithDefault(java.lang.String key)
public java.lang.Object localizedValueForKey(java.lang.String key)
session.localizer.@locale.getLanguage
indicates that
the methods on ERXLocalizer itself should be called instead of
searching the strings file for a '@locale.getLanguage' key.
key
- the keyPath string
public java.lang.String localizedStringForKeyWithDefault(java.lang.String key)
public java.lang.String localizedStringForKey(java.lang.String key)
public java.lang.String localizedDisplayNameForKey(java.lang.String prefix, java.lang.String key)
prefix
- key
- public java.lang.String localizedTemplateStringForKeyWithObject(java.lang.String key, java.lang.Object o1)
public java.lang.String localizedTemplateStringForKeyWithObjectOtherObject(java.lang.String key, java.lang.Object o1, java.lang.Object o2)
protected java.lang.String plurify(java.lang.String str, int howMany)
protected java.lang.String singularify(java.lang.String str)
protected java.lang.String applyRules(java.lang.String str, java.util.Map rules)
str
- the input stringrules
- the rules to apply
public java.lang.String plurifiedStringWithTemplateForKey(java.lang.String key, java.lang.String name, int count, java.lang.Object helper)
public java.lang.String plurifiedString(java.lang.String name, int count)
name
- count
- public java.lang.String singularifiedString(java.lang.String value)
value
- the value to singularify
public java.lang.String toString()
toString
in class java.lang.Object
public java.text.Format localizedDateFormatForKey(java.lang.String formatString)
formatString
- public java.text.Format localizedNumberFormatForKey(java.lang.String formatString)
formatString
-
public void setLocalizedNumberFormatForKey(java.text.Format formatter, java.lang.String pattern)
formatter
- pattern
- public java.util.Locale locale()
public void setLocale(java.util.Locale value)
public void setLocalizedDateFormatForKey(com.webobjects.foundation.NSTimestampFormatter formatter, java.lang.String pattern)
formatter
- pattern
- public static boolean useLocalizedFormatters()
public java.lang.String languageCode()
public static boolean fallbackToDefaultLanguage()
|
Last updated: Tue, Feb 21, 2017 05:45 PM CET | |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |