CLI

CLI設定ファイルの変更(Strings)

本コンテンツはPhrase Language AIの機械翻訳により、英語から翻訳されています。

ヒント

詳細な情報については、Developer Hubを参照してください。

プッシュとプル

プッシュ

$ phrase push 

pushコマンドは、ローカルプロジェクトディレクトリにあるファイルをアップロードします。.phrase.ymlファイルを使用してアップロードするファイルを指定し、追加のパラメータを設定します。<tag>プレースホルダーを使用して、tagsに基づいてキーを別のファイルをダウンロードすることもできます。

プル

$ phrase pull 

pushコマンドと似ていますが、例外グロビングは使用できません。プレースホルダーを使用する場合は、可能な限り <locale_name> を使用します。特定のタグを持つキーを持つファイルを pull するには、 tags パラメータを使用します。

phrase:
  pull:
    targets:
    - file: path/to/file/<locale_name>.yml
      params:
        tags:tag_name

<tag> プレースホルダーを使用するには、必要な tags が params セクションに記載されている必要があります。

パラメータ

pushおよびpullコマンドは、.phrase.ymlファイル内で設定できます。

備考

uploads API エンドポイントのすべてのオプションは、push コマンドに対応しています。

locales download API エンドポイントのすべてのオプションは、pull コマンドに対応しています。

Push の例:

push:
  sources:
  - file: ./locales/en.json
    params:
      update_translations: true 

Pull の例:

pull:
  targets:
  - file: "./locales/example.yml"
    params:
      include_unverified_translations: true

ファイル形式オプション

ファイル形式によっては、ファイル形式オプションをパラメータ セクションに適用できます。ファイル形式オプションは uploads、downloads、またはその両方に適用できます。

ファイル形式の例:

params:
  format_options:
    convert_placeholder: true

一部のファイル形式では、ファイル構文をより詳細に制御できます:

phrase:
  pull:
    targets:
    - file: file.xml
      params:
        format_options:
          convert_placeholder: true

  push:
    sources:
    - file: file.csv
      params:
        format_options:
          column_separator: ";"

プレースホルダーとグロビング

以下のプレースホルダーとグロビング演算子をファイルエントリ内のパスに含めることができます。

  • <locale_name>

    一意のロケール名。

  • <locale_code>

    RFC 5646 準拠のロケール識別子。ロケールコードは一意である必要はないため、異なる名前のロケールが同じコードで存在することができます。

  • <tag>

    tagsを使用してキーをグループ化します。tagsを使用すると、元のファイル構造を維持できます。

グロビング

***はグロビング演算子です。単一のアスタリスク * は、パス内のすべてのフォルダをスキップします。ダブルアスタリスク ** は、標準のグロビング演算子と類似しており、再帰的、非網羅的なマッチングのために任意の文字と一致します。

例:

# a file pattern

./abc/**/*.yml
# with a few files on your system

./abc/defg/en.yml

./abc/es.yml

./fr.yml
# selects

./abc/defg/en.yml

./abc/es.yml

pull コマンドを使用してファイルをダウンロードする場合、./abc/defg/<locale_name>.ymlのような明示的なファイルパターンを提供し、./**/*.ymlではなくします。

アップロード待ち

すべてのuploadsは非同期で処理されます。アップロードを待つには、--waitフラッグを適用します。pushは、各ファイルのアップロードを待機し、成功したか失敗したかを返します。

使用例

指定ロケールにファイルをアップロード

locale_idで指定のen.jsonファイルを./locales/ディレクトリにアップロードします(ロケールはすでに存在している必要があります)。

Update_translationsfalseに設定されているため、新しいキーと翻訳のみがインポートされます。trueに設定した場合、クライアントは既存の翻訳に対するローカルな変更もインポートし、既存のコンテンツはすべて上書きされます。

phrase:
  access_token: ACCESS_TOKEN
  project_id: PROJECT_ID
  file_format: nested_json

  push:
    sources:
    - file: ./locales/en.json
      params:
        update_translations: false
        locale_id: YOUR_LOCALE_ID # ロケールはリモートに存在する必要があります

備考

インポートされた翻訳エントリは削除できません。必要に応じて、関連するAPIエンドポイント経由で翻訳をempty値に更新してください。

Ruby on Rails: 指定されたファイル形式のアップロード

./config/locales/にある.ymlで終わるすべてのファイルをアップロード。Ruby on RailsのYAMLファイルにはロケール情報が含まれているため、ロケールを明示的に指定する必要はありません。Update_translationstrueに設定されているため、翻訳に対する変更はすべてインポートされ、既存のデータは上書きされます。

phrase:
  push:
    sources:
    - file: ./config/locales/*.yml
      params:
        update_translations: true
        file_format: yml

一致iOS Strings

すべてのiOS Stringsファイルと.lprojフォルダ内のLocalizable.stringsという名前のファイルを一致させます。

<locale_code>は、ロケールを作成し識別するために、/の後と.lprojの前に一致するすべての内容です。

update_translationsパラメータが省略されており、falseに設定した場合と同じ結果になります。

phrase:
  push:
    sources:
    - file: "./<locale_code>.lproj/Localizable.strings"
      params:
        file_format: strings

1つのローカライゼーションプロジェクトに対して複数のStringsプロジェクトを維持

設定ファイルを編集し、翻訳をより小さなカテゴリに分割してプロジェクトの範囲を制限できます。

フレームワークの設定例

要件に合わせて設定ファイルを変更し、原文管理システムまたはバージョン管理システムにチェックインします。

Rails

phrase:
  access_token: ACCESS_TOKEN
  project_id: PROJECT_ID
  file_format: "yml"

  push:
    sources:
    - file: "./config/locales/*.yml"

  pull:
    targets:
    - file: "./config/locales/<locale_name>.yml"

iOS strings

phrase:

  access_token: ACCESS_TOKEN
  project_id: PROJECT_ID
  file_format: "strings"

  push:
    sources:
    - file: "./<locale_code>.lproj/Localizable.strings"

  pull:
    targets:
    - file: "./<locale_code>.lproj/Localizable.strings"
    - file: "./<locale_code>.lproj/Localizable.stringsdict"
      params:
        #file_formatは上書き可能です
        file_format: "stringsdict"

Android XML

Androidでは、ファイルパターンとして標準のISO言語コードを使用しません。.phrase.ymlで必要なパターンを指定してください。

各ロケールのために別々のプルターゲットを定義する代わりに、グローバルなlocale_mapping設定を使用し、<locale_name>プレースホルダーと組み合わせてください。CLIは、対応するロケールのマッピングからカスタム名を使用し、他のすべての言語に対してデフォルトのPhraseロケールコードにフォールバックします。

例:

phrase:
  access_token: ACCESS_TOKEN
  project_id: PROJECT_ID
  file_format: "xml"

  #PhraseロケールをAndroid特有のディレクトリ名にマッピングします
  locale_mapping:
    en-US: values
    de-DE: values-de-rDE
    fr-FR: values-fr

  push:
    sources:
      #ソースファイルはデフォルト言語であり、'values'にマッピングされています
      - file: ./app/src/main/res/values/strings.xml
        params:
          locale_id: en-US #Phraseのソースロケールと一致する必要があります

  pull:
    targets:
      #マッピングによって置き換えられる<locale_name>プレースホルダーを使用します
      - file: ./app/src/main/res/<locale_name>/strings.xml

明示的に設定されたロケールの例

英語をデフォルト言語、ドイツ語ロケール、オーストリアドイツ語のドイツ語地域ロケールとする例:

phrase:
  access_token: ACCESS_TOKEN
  project_id: PROJECT_ID
  file_format: xml
  
  pull:
    targets:
    - file: ./app/src/main/res/values/strings.xml
      params:
        file_format: xml
        #英語のユニークロケールID
        locale_id: LOCALE_ID
    - file: ./app/src/main/res/values-de/strings.xml
      params:
        file_format: xml
        # ユニークロケールID(ドイツ語)
        locale_id: LOCALE_ID
    - file: ./app/src/main/res/values-de-rAU/strings.xml
      params:
        file_format: xml
        # ユニークロケールID(オーストリア)
        locale_id: LOCALE_ID
  push:
    sources:
    - file: ./app/src/main/res/values/strings.xml
      params:
        file_format: xml
        locale_id: LOCALE_ID
    - file: ./app/src/main/res/values-de/strings.xml
      params:
        file_format: xml
        locale_id: LOCALE_ID
    - file: ./app/src/main/res/values-de-rAU/strings.xml
      params:
        file_format: xml
        locale_id: LOCALE_ID

マルチプラットフォームの例

複数のターゲットに対して1つの設定で自動的に翻訳をプッシュおよびプルします。 

phrase:
  access_token: ACCESS_TOKEN
  project_id: PROJECT_ID
  file_format: nested_json

  push:
    sources:
      # Web JSON
      - file: "apps/web/src/assets/i18n/.json"
        params:
          file_format: nested_json
          locale_id: LOCALE_ID
      # Android XML
      - file: "apps/android/app/src/main/res/values-/strings.xml"
        params:
          file_format: android
          locale_id: LOCALE_ID
      # iOS Strings
      - file: "apps/ios/.lproj/Localizable.strings"
        params:
          file_format: strings
          locale_id: LOCALE_ID

  pull:
    targets:
      - file: "apps/web/src/assets/i18n/.json"
        params:
          file_format: nested_json
          locale_id: LOCALE_ID
      - file: "apps/android/app/src/main/res/values-/strings.xml"
        params:
          file_format: android
          locale_id: LOCALE_ID
      - file: "apps/ios/.lproj/Localizable.strings"
        params:
          file_format: strings
          locale_id: LOCALE_ID
この記事は役に立ちましたか?

Sorry about that! In what way was it not helpful?

The article didn’t address my problem.
I couldn’t understand the article.
The feature doesn’t do what I need.
Other reason.

Note that feedback is provided anonymously so we aren't able to reply to questions.
If you'd like to ask a question, submit a request to our Support team.
Thank you for your feedback.