Cordova-globalisation
提供:Dev Guides
Cordova-グローバリゼーション
このプラグインは、ユーザーのロケール言語、日付と時間帯、通貨などに関する情報を取得するために使用されます。
手順1-グローバリゼーションプラグインのインストール
- コマンドプロンプト*を開き、次のコードを入力してプラグインをインストールします
ステップ2-ボタンを追加する
後で作成するさまざまなメソッドを呼び出せるように、いくつかのボタンを indexl に追加します。
手順3-イベントリスナーの追加
イベントリスナーは、 index.js ファイルの getDeviceReady 関数内に追加され、使用を開始する前にアプリとCordovaがロードされるようにします。
ステップ4A-言語機能
使用している最初の関数は、クライアントのデバイスのBCP 47言語タグを返します。 getPreferredLanguage メソッドを使用します。 この関数には、onSuccessと onError の2つのパラメーターがあります。 この関数を index.js に追加しています。
Cordova Globalization Language
ステップ4B-ロケール機能
この関数は、クライアントのローカル設定のBCP 47タグを返します。 この関数は、前に作成した関数と似ています。 唯一の違いは、今回は getLocaleName メソッドを使用していることです。
ステップ4C-日付関数
この関数は、クライアントのロケールとタイムゾーン設定に従って日付を返すために使用されます。 date パラメーターは現在の日付で、 options パラメーターはオプションです。
これでアプリを実行し、 DATE ボタンを押して現在の日付を確認できます。
最後に示す関数は、クライアントのデバイス設定とISO 4217通貨コードに従って通貨値を返すことです。 概念が同じであることがわかります。
このプラグインは他の方法を提供します。 以下の表ですべて見ることができます。
method | parameters | details |
---|---|---|
getPreferredLanguage | onSuccess, onError | Returns client’s current language. |
getLocaleName | onSuccess, onError | Returns client’s current locale settings. |
dateToString | date, onSuccess, onError, options | Returns date according to client’s locale and timezone. |
stringToDate | dateString, onSuccess, onError, options | Parses a date according to client’s settings. |
getCurrencyPattern | currencyCode, onSuccess, onError | Returns client’s currency pattern. |
getDatePattern | onSuccess, onError, options | Returns client’s date pattern. |
getDateNames | onSuccess, onError, options | Returns an array of names of the months, weeks or days according to client’s settings. |
isDayLightSavingsTime | date, successCallback, errorCallback | Used to determine if the daylight saving time is active according to client’s time zone and calendar. |
getFirstDayOfWeek | onSuccess, onError | Returns the first day of the week according to client settings. |
numberToString | number, onSuccess, onError, options | Returns number according to client’s settings. |
stringToNumber | string, onSuccess, onError, options | Parses a number according to client’s settings. |
getNumberPattern | onSuccess, onError, options | Returns the number pattern according to client’s settings. |