public class ERXLocalizer extends Object implements com.webobjects.foundation.NSKeyValueCoding, com.webobjects.foundation.NSKeyValueCodingAdditions
"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.
"this is a test"; = "some test";
"unittest.key.path.as.string" = "some test";
"unittest" = {
"key" = {
"path" = {
"as" = {
"dict"="some test";
};
};
};
};
メモ: unittest
のみを呼ぶと、String の替わりに dictionary を取得します。
Stringよりも複雑なオブジェクトをローカライズが可能です。
valueForKeyPath("session.localizer.this is a test")
valueForKeyPath("session.localizer.unittest.key.path.as.string")
valueForKeyPath("session.localizer.unittest.key.path.as.dict")
sessionの無いアプリケーションの場合は他の方法を使用することでリクエスト言語を取得します。
ERXLocalizer l = ERXLocalizer.localizerForLanguages(languagesThisUserCanHandle) or
ERXLocalizer l = ERXLocalizer.localizerForLanguage("German")
次のデフォルト情報をセットできます (カレント・デフォルト値含むでリストされています):
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)
言語体系の英語複数形処理のメソッドもあります。(y -> ies, x -> xes など)
dict に追加することで、自分の複数形処理ルールを設定できます。
localizerExceptions = {
"Table.0" = "Table";
"Table" = "Tables";
...
};
Localizable.strings ファイル内 Table.0
は"Table"がない、 Table.1
は"Table"が一つと
Table
はそれ以外の数のことです。 メモ: 他のすべてのキーと違って、翻訳済み値をキーとして使用します。
(ドイツ語では "Table" の替わりに "Tisch" を使います)
なぜなら、このメソッドは良くd2wContext.displayNameForPropertyのようなメソッドより呼ばれ、既に翻訳済みなのです。
Modifier and Type | Class and Description |
---|---|
static class |
ERXLocalizer.Observer |
com.webobjects.foundation.NSKeyValueCodingAdditions.DefaultImplementation, com.webobjects.foundation.NSKeyValueCodingAdditions.Utility
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.MapImplementation, com.webobjects.foundation.NSKeyValueCoding.Null<T>, com.webobjects.foundation.NSKeyValueCoding.UnknownKeyException, com.webobjects.foundation.NSKeyValueCoding.ValueAccessor
Modifier and Type | Field and Description |
---|---|
protected Map<String,Format> |
_dateFormatters |
protected Map<String,Format> |
_numberFormatters |
protected NSMutableDictionary<String,Object> |
cache |
static String |
KEY_LOCALIZER_EXCEPTIONS |
protected String |
language |
protected Locale |
locale |
static String |
LocalizationDidResetNotification |
Constructor and Description |
---|
ERXLocalizer(String aLanguage) |
Modifier and Type | Method and Description |
---|---|
protected void |
addEntriesToCache(NSDictionary<String,Object> dict) |
protected void |
addToCreatedKeys(Object value,
String key)
キー・リストに追加します
|
protected String |
applyRules(String str,
Map<Pattern,String> 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<String> |
availableLanguages()
使用可能な言語を配列として戻します
|
NSDictionary<String,Object> |
cache()
キャシュを戻します
|
NSDictionary<String,Object> |
createdKeys()
作成されているキーをdictionaryとして戻します
|
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<Pattern,String> |
defaultPlurifyRules()
Returns the default plurify rules for this language.
|
protected Map<Pattern,String> |
defaultSingularifyRules()
Returns the default singularify rules for this language.
|
void |
dumpCreatedKeys()
キー・リストをダンプします
|
static ERXLocalizer |
englishLocalizer()
英語のローカライザーを戻します
|
static boolean |
fallbackToDefaultLanguage()
デフォルト言語に戻ります。
|
static NSArray<String> |
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(com.webobjects.eocontrol.EOClassDescription classDescription,
String key)
Returns a localized string for a given entity class description.
|
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"
指定の prefix と key のローカライズ済みの文字列を戻します。
例えば、 |
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)
指定のキーのローカライズ済み文字列を取得し、ERXSimpleTemplateParserに処理させてから戻します
|
String |
localizedTemplateStringForKeyWithObjectOtherObject(String key,
Object o1,
Object o2)
指定のキーのローカライズ済み文字列を取得し、ERXSimpleTemplateParserに処理させてから戻します
|
Object |
localizedValueForKey(String key)
Returns the localized value for a key.
|
Object |
localizedValueForKeyWithDefault(String key)
キーを使って、ローカライズ・オブジェクトを戻します
@ キーパス
session.localizer.@locale.getLanguage で
キーファイルを探すかわりに ERXLocalizer メソッドを実行します。 |
static ERXLocalizer |
localizerForLanguage(String language)
Get a localizer for a specific language.
|
static ERXLocalizer |
localizerForLanguages(NSArray<String> languages)
Gets the best localizer for a set of languages.
|
static ERXLocalizer |
localizerForRequest(com.webobjects.appserver.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<Pattern,String> |
plurifyRules()
Returns the plurify rules for the current language.
|
protected NSDictionary |
readPropertyListFromFileInFramework(String fileName,
String framework,
NSArray<String> languages) |
static void |
resetCache()
Resets the localizer cache.
|
static void |
setAvailableLanguages(NSArray<String> 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<String> value)
ウォッチするファイル名をセットします
|
static void |
setFrameworkSearchPath(NSArray<String> value)
フレームワーク検索パスをセットします
|
static void |
setIsLocalizationEnabled(boolean value)
ローカライズ可能かどうかをセットします
|
void |
setLocale(Locale value)
ロケールをゲット
|
void |
setLocalizedDateFormatForKey(com.webobjects.foundation.NSTimestampFormatter formatter,
String pattern)
ローカライズ済み TimestampFormatter を保存します。
|
void |
setLocalizedNumberFormatForKey(Format formatter,
String pattern)
ローカライズ済み NumberFormatter を保存します。
|
static void |
setLocalizerForLanguage(ERXLocalizer l,
String language)
ローカライザーをセットします
|
String |
singularifiedString(String value)
Returns a singularified string
単数形処理されている文字列を戻します
|
protected String |
singularify(String str) |
protected Map<Pattern,String> |
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) |
public static final String KEY_LOCALIZER_EXCEPTIONS
public static final String LocalizationDidResetNotification
protected NSMutableDictionary<String,Object> cache
protected String language
protected Locale locale
public ERXLocalizer(String aLanguage)
public static void initialize()
public static boolean isLocalizationEnabled()
public static void setIsLocalizationEnabled(boolean value)
value
- - true 可能
public static ERXLocalizer currentLocalizer()
public static void setCurrentLocalizer(ERXLocalizer currentLocalizer)
ERXThreadStorage
ERXThreadStorage
を参照
currentLocalizer
- public static ERXLocalizer defaultLocalizer()
public static ERXLocalizer englishLocalizer()
public static ERXLocalizer localizerForRequest(com.webobjects.appserver.WORequest request)
request
- - WORequestpublic static void resetCache()
protected void addToCreatedKeys(Object value, String key)
value
- - オブジェクトkey
- - キー
public static ERXLocalizer localizerForLanguages(NSArray<String> languages)
languages
-
public static ERXLocalizer localizerForLanguage(String language)
null
a localizer for the defaultLanguage()
is returned.
defaultLanguage()
が戻ります。
language
- public static String defaultLanguage()
er.extensions.ERXLocalizer.defaultLanguage
property.
er.extensions.ERXLocalizer.defaultLanguage
プロパティー
を戻します
public static void setDefaultLanguage(String value)
value
-
public static NSArray<String> fileNamesToWatch()
public static void setFileNamesToWatch(NSArray<String> value)
value
- - ファイル配列
public static NSArray<String> availableLanguages()
public static void setAvailableLanguages(NSArray<String> value)
value
- - 使用可能な言語のNSArray
public static NSArray<String> frameworkSearchPath()
public static void setFrameworkSearchPath(NSArray<String> value)
value
- - フレームワーク検索
protected static ERXLocalizer createLocalizerForLanguage(String language, boolean pluralForm)
er.extensions.ERXLocalizer.pluralFormClassName
or
er.extensions.ERXLocalizer.nonPluralFormClassName
.
er.extensions.ERXLocalizer.pluralFormClassName
or
er.extensions.ERXLocalizer.nonPluralFormClassName
.
language
- pluralForm
- public static void setLocalizerForLanguage(ERXLocalizer l, String language)
l
- - ERXLocalizer ローカライザーlanguage
- - 言語
public NSDictionary<String,Object> cache()
public void load()
protected Map<Pattern,String> 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.
er.extensions.ERXLocalizer.en.plurifyRules=(.*)person$=$1people:(.*)man$=$1men
が次のように
er.extensions.ERXLocalizerr.en.plurifyRules=pattern1=replacement1:pattern2=replacement2:etc
各言語のルール不足分で、デフォルト・ルールは英語です。
protected Map<Pattern,String> defaultPlurifyRules()
protected Map<Pattern,String> 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.
er.extensions.ERXLocalizer.en.singularifyRules=(.*)person$=$1people:(.*)man$=$1men
が次のように
er.extensions.ERXLocalizer.en.singularifyRules=pattern1=replacement1:pattern2=replacement2:etc
各言語のルール不足分で、デフォルト・ルールは英語です。
protected Map<Pattern,String> defaultSingularifyRules()
protected void addEntriesToCache(NSDictionary<String,Object> dict)
protected NSDictionary readPropertyListFromFileInFramework(String fileName, String framework, NSArray<String> languages)
public Object valueForKey(String key)
localizedStringForKey
.valueForKey
in interface com.webobjects.foundation.NSKeyValueCoding
key
- to resolve a localized variant ofpublic Object valueForKeyPath(String key)
valueForKeyPath
in interface com.webobjects.foundation.NSKeyValueCodingAdditions
public void takeValueForKey(Object value, String key)
takeValueForKey
in interface com.webobjects.foundation.NSKeyValueCoding
public void takeValueForKeyPath(Object value, String key)
takeValueForKeyPath
in interface com.webobjects.foundation.NSKeyValueCodingAdditions
public String language()
public NSDictionary<String,Object> createdKeys()
public void dumpCreatedKeys()
public Object localizedValueForKeyWithDefault(String key)
session.localizer.@locale.getLanguage
で
キーファイルを探すかわりに ERXLocalizer メソッドを実行します。key
- - キーpublic Object localizedValueForKey(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.
session.localizer.@locale.getLanguage
で
キーファイルを探すかわりに ERXLocalicer メソッドを実行します。
key
- public String localizedStringForKeyWithDefault(String key)
key
- - キーpublic String localizedStringForKey(String key)
key
- - キーpublic String localizedDisplayNameForKey(String prefix, String key)
s = <ERXLocalizer>.localizedDisplayNameForKey( "Tester", "samplekey" );
Tester.samplekey になりますprefix
-
key
-
public String localizedDisplayNameForKey(com.webobjects.eocontrol.EOClassDescription classDescription, String key)
classDescription
- the entity class descriptionkey
- the attribute namepublic String localizedTemplateStringForKeyWithObject(String key, Object o1)
key
- - キーo1
- - オブジェクトpublic String localizedTemplateStringForKeyWithObjectOtherObject(String key, Object o1, Object o2)
key
- - キーo1
- - オブジェクトo2
- - オブジェクトprotected String applyRules(String str, Map<Pattern,String> rules)
str
- the input stringrules
- the rules to applypublic 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
- public String toString()
public 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(com.webobjects.foundation.NSTimestampFormatter formatter, String pattern)
formatter
-
pattern
-
public static boolean useLocalizedFormatters()
true
ローカライズ・フォーマッタを使用する場合
public String languageCode()
public static boolean fallbackToDefaultLanguage()
Copyright © 2002 – 2020 Project Wonder.