|
Project Wonder 5.0.0.8794 | |||||||||
| 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 |
|---|
NSKeyValueCodingAdditions.DefaultImplementation, NSKeyValueCodingAdditions.Utility |
| Field Summary | |
|---|---|
protected Hashtable |
_dateFormatters
|
protected Hashtable |
_numberFormatters
|
protected NSMutableDictionary |
cache
|
protected static Logger |
createdKeysLog
|
static String |
KEY_LOCALIZER_EXCEPTIONS
|
protected String |
language
|
protected Locale |
locale
|
static String |
LocalizationDidResetNotification
|
protected static Logger |
log
|
| Fields inherited from interface com.webobjects.foundation.NSKeyValueCodingAdditions |
|---|
_CLASS, _KeyPathSeparatorChar, KeyPathSeparator |
| Constructor Summary | |
|---|---|
ERXLocalizer(String aLanguage)
|
|
| Method Summary | |
|---|---|
protected void |
addEntriesToCache(NSDictionary dict)
|
protected void |
addToCreatedKeys(Object value,
String key)
|
protected String |
applyRules(String str,
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 NSArray |
availableLanguages()
|
NSDictionary |
cache()
|
NSDictionary |
createdKeys()
|
protected static ERXLocalizer |
createLocalizerForLanguage(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 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 Map |
defaultPlurifyRules()
Returns the default plurify rules for this language. |
protected Map |
defaultSingularifyRules()
Returns the default singularify rules for this language. |
void |
dumpCreatedKeys()
|
static boolean |
fallbackToDefaultLanguage()
|
static NSArray |
fileNamesToWatch()
|
static NSArray<String> |
frameworkSearchPath()
|
static void |
initialize()
|
static boolean |
isLocalizationEnabled()
|
String |
language()
|
String |
languageCode()
|
void |
load()
|
Locale |
locale()
|
Format |
localizedDateFormatForKey(String formatString)
Returns a localized date formatter for the given key. |
String |
localizedDisplayNameForKey(String prefix,
String key)
Returns a localized string for the given prefix and keyPath, inserting it "prefix.keyPath" = "Key Path"; Also tries to find "Key Path" |
Format |
localizedNumberFormatForKey(String formatString)
Returns a localized number formatter for the given key. |
String |
localizedStringForKey(String key)
|
String |
localizedStringForKeyWithDefault(String key)
|
String |
localizedTemplateStringForKeyWithObject(String key,
Object o1)
|
String |
localizedTemplateStringForKeyWithObjectOtherObject(String key,
Object o1,
Object o2)
|
Object |
localizedValueForKey(String key)
|
Object |
localizedValueForKeyWithDefault(String key)
|
static ERXLocalizer |
localizerForLanguage(String language)
|
static ERXLocalizer |
localizerForLanguages(NSArray languages)
Gets the best localizer for a set of languages. |
static ERXLocalizer |
localizerForRequest(WORequest request)
|
String |
plurifiedString(String name,
int count)
Returns a plurified string |
String |
plurifiedStringWithTemplateForKey(String key,
String name,
int count,
Object helper)
|
protected String |
plurify(String str,
int howMany)
|
protected Map |
plurifyRules()
Returns the plurify rules for the current language. |
protected NSDictionary |
readPropertyListFromFileInFramework(String fileName,
String framework,
NSArray languages)
|
static void |
resetCache()
Resets the localizer cache. |
static void |
setAvailableLanguages(NSArray value)
|
protected void |
setCacheValueForKey(Object value,
String key)
|
static void |
setCurrentLocalizer(ERXLocalizer currentLocalizer)
Sets a localizer for the current thread. |
static void |
setDefaultLanguage(String value)
Sets the default language. |
static void |
setFileNamesToWatch(NSArray value)
|
static void |
setFrameworkSearchPath(NSArray value)
|
static void |
setIsLocalizationEnabled(boolean value)
|
void |
setLocale(Locale value)
|
void |
setLocalizedDateFormatForKey(NSTimestampFormatter formatter,
String pattern)
|
void |
setLocalizedNumberFormatForKey(Format formatter,
String pattern)
|
static void |
setLocalizerForLanguage(ERXLocalizer l,
String language)
|
String |
singularifiedString(String value)
Returns a singularified string |
protected String |
singularify(String str)
|
protected Map |
singularifyRules()
Returns the singularify rules for the current language. |
void |
takeValueForKey(Object value,
String key)
|
void |
takeValueForKeyPath(Object value,
String key)
|
String |
toString()
|
static boolean |
useLocalizedFormatters()
|
Object |
valueForKey(String key)
Cover method that calls localizedStringForKey. |
Object |
valueForKeyPath(String key)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String KEY_LOCALIZER_EXCEPTIONS
protected static final Logger log
protected static final Logger createdKeysLog
public static final String LocalizationDidResetNotification
protected NSMutableDictionary cache
protected Hashtable _dateFormatters
protected Hashtable _numberFormatters
protected String language
protected Locale locale
| Constructor Detail |
|---|
public ERXLocalizer(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 localizerForRequest(WORequest request)
public static void resetCache()
protected void addToCreatedKeys(Object value,
String key)
public static ERXLocalizer localizerForLanguages(NSArray languages)
languages - public static ERXLocalizer localizerForLanguage(String language)
public static String defaultLanguage()
er.extensions.ERXLocalizer.defaultLanguage property.
public static void setDefaultLanguage(String value)
value - public static NSArray fileNamesToWatch()
public static void setFileNamesToWatch(NSArray value)
public static NSArray availableLanguages()
public static void setAvailableLanguages(NSArray value)
public static NSArray<String> frameworkSearchPath()
public static void setFrameworkSearchPath(NSArray value)
protected static ERXLocalizer createLocalizerForLanguage(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,
String language)
public NSDictionary cache()
public void load()
protected 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 Map defaultPlurifyRules()
protected 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 Map defaultSingularifyRules()
protected void addEntriesToCache(NSDictionary dict)
protected NSDictionary readPropertyListFromFileInFramework(String fileName,
String framework,
NSArray languages)
public Object valueForKey(String key)
localizedStringForKey.
valueForKey in interface NSKeyValueCodingkey - to resolve a localized varient of
protected void setCacheValueForKey(Object value,
String key)
public Object valueForKeyPath(String key)
valueForKeyPath in interface NSKeyValueCodingAdditions
public void takeValueForKey(Object value,
String key)
takeValueForKey in interface NSKeyValueCoding
public void takeValueForKeyPath(Object value,
String key)
takeValueForKeyPath in interface NSKeyValueCodingAdditionspublic String language()
public NSDictionary createdKeys()
public void dumpCreatedKeys()
public Object localizedValueForKeyWithDefault(String key)
public Object localizedValueForKey(String key)
public String localizedStringForKeyWithDefault(String key)
public String localizedStringForKey(String key)
public String localizedDisplayNameForKey(String prefix,
String key)
prefix - key -
public String localizedTemplateStringForKeyWithObject(String key,
Object o1)
public String localizedTemplateStringForKeyWithObjectOtherObject(String key,
Object o1,
Object o2)
protected String plurify(String str,
int howMany)
protected String singularify(String str)
protected String applyRules(String str,
Map rules)
str - the input stringrules - the rules to apply
public String plurifiedStringWithTemplateForKey(String key,
String name,
int count,
Object helper)
public String plurifiedString(String name,
int count)
name - count - public String singularifiedString(String value)
value - the value to singularify
public String toString()
toString in class Objectpublic Format localizedDateFormatForKey(String formatString)
formatString - public Format localizedNumberFormatForKey(String formatString)
formatString -
public void setLocalizedNumberFormatForKey(Format formatter,
String pattern)
formatter - pattern - public Locale locale()
public void setLocale(Locale value)
public void setLocalizedDateFormatForKey(NSTimestampFormatter formatter,
String pattern)
formatter - pattern - public static boolean useLocalizedFormatters()
public String languageCode()
public static boolean fallbackToDefaultLanguage()
|
Last updated: Thu, Jan 8, 2009 12:32 PM EST | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||