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.
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.
ローカライズ用の KVC アクセスを実現します。 すべてのフレームワーク内のファイルセットをモニタし、指定キーと言語に従って String を戻します。 次のキーがファイル内で可能です。 "this is a test"; = "some test"; "unittest.key.path.as.string" = "some test"; "unittest" = { "key" = { "path" = { "as" = { "dict"="some test"; }; }; }; };
メモ: unittest
のみを呼ぶと、String の替わりに dictionary を取得します。 Stringよりも複雑なオブジェクトをローカライズが可能です。
session のベースクラスが ERXSession であれば、コンポーネント内に次のコードを実行できます。 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のようなメソッドより呼ばれ、既に翻訳済みなのです。