.phrase.yml
文件用于存储重复使用的命令行参数。
支持的参数:
-
project_id
项目的 ID。
-
file_format
源和目标条目中未明确指定时使用的文件格式。
-
per_page
分页响应中返回的条目数。
配置文件示例。
推送
$ phrase push
Push
命令上传本地项目目录中的文件。使用 .phrase.yml
文件指定要上传的文件并设置其他参数。<tag>
占位符也可用于根据键的标签将其下载到单独的文件中。
拉取
$ phrase pull
与 push
命令类似,但 globbing 除外。使用占位符时,尽量使用 <locale_name>
。要拉取带有特定标签的文件键,请使用 tags
参数:
phrase: pull: targets: - file: path/to/file/<locale_name>.yml params: tags:tag_name
要使用 <tag>
占位符,必须在 params
部分中列出所需的标签。
参数
Push
和 pull
命令可以在 .phrase.yml
文件中配置。Push 选项与 上传
API 端点相同,pull 选项与 区域下载
API 端点相同。
Push 示例:
push: sources: - file: ./locales/en.json params: update_translations: true
Pull 示例:
pull: targets: - file: "./locales/example.yml" params: include_unverified_translations: true
根据文件格式,格式选项可以应用于参数部分。格式选项可以应用于上传、下载或两者皆有。
格式示例:
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: ";"
以下占位符和通配符操作符可以放在文件条目的路径中:
通配符
*
和 **
是通配符操作符。单个星号 *
跳过路径中的任意文件夹。双星号 **
与标准通配符操作符一样,用于递归地、非穷尽地匹配任意字符。
示例:
# 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
。
上传文件到指定区域
使用指定的 locale_id
将 en.json
文件上传到 ./locales/
目录(区域必须已经存在)。
Update_translations
设置为 false,仅导入新键和翻译。如果设置为 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_translations
设置为 true,因此所有对翻译的更改都将在导入时覆盖现有数据。
phrase: push: sources: - file: ./config/locales/*.yml params: update_translations: true file_format: yml
匹配 iOS 字符串
将所有 iOS 字符串文件与 .lproj
文件夹中名为 Localizable.strings
的文件匹配。
<locale_code>
是指 /
之后和 .lproj
之前的所有内容,用于创建和识别区域。
无需 update_translations
参数,效果与将其设置为 false 相同。
phrase: push: sources: - file: "./<locale_code>.lproj/Localizable.strings" params: file_format: 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 字符串
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