CLI

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

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

.phrase.ymlファイルは、再利用可能なコマンドライン引数の保存に使用されます。

サポートされている引数:

  • project_id

    プロジェクトの ID。

  • file_format

    原文と訳文のエントリで明示的に指定されていない場合に使用されるファイル形式。

  • per_page

    ページ分割されたレスポンスで返されるアイテム数。

設定ファイルのサンプル。

プッシュとプル

Push

$ 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ファイル内で設定できます。push オプションは uploads API エンドポイントと同じで、pull オプションは locales download API エンドポイントと同じです。

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 コマンドを使用してファイルをダウンロードする場合、 ./**/*.ymlではなく ./abc/defg/<locale_name>.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 # the locale must exist remotely

備考

インポートされた翻訳エントリは削除できません。必要に応じて、関連 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 can be overwritten
        file_format: "stringsdict"

Android XML

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

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

  push:
    sources:
    - file: "./res/values-<locale_code>/strings.xml"

  pull:
    targets:
    - file: "./res/values-<locale_code>/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
        # Unique locale id for English
        locale_id:LOCALE_ID
    - file: ./app/src/main/res/values-de/strings.xml
      params:
        file_format: xml
        # Unique locale id for German
        locale_id:LOCALE_ID
    - file: ./app/src/main/res/values-de-rAU/strings.xml
      params:
        file_format: xml
        # Unique locale id for Austrian
        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
この記事は役に立ちましたか?

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.