翻译

Website Translation (Strings)

文本由 Phrase Language AI 从英语机器翻译而得。

Play Framework for Strings

Play Framework 是一个用于 Java 和 Scala 的高速度 Web 框架。

准备应用程序

确保本地化文件格式正确,并且 Play 属性使用 UTF-8 编码。

要准备应用程序,请按照以下步骤操作:

  1. 将所需语言添加到 application.conf 中,优先级按区域顺序降序设置 (en 为最重要,de 第二,依此类推):

    application.langs="en,de,fr"
  2. messages.enmessages.demessages.fr 文件添加到 conf/ 文件夹。

示例:

# 我的软件项目(描述)
project.name=某个名称
title1=AwesomeApp

# 你永远不会有足够的标题!
more_titles=Another Title

Rails for Ruby i18n in Strings

要使用 Rails for Ruby i18n,请按照以下步骤操作:

  1. 下载最新的 client 并按照 设置说明 操作。

  2. 要初始化项目配置,请遵循说明

    $ phrase init

    按照步骤配置项目的源和目标。选择 .yml 作为区域文件格式。

  3. 如果现有的本地化文件存储在默认位置 ./config/locales,请使用推送命令上传数据:

    $ phrase push

    在源路径中找到的所有现有本地化文件都已上传到项目中。现有翻译现在在 Phrase 中,可以添加新的语言或键。

  4. 下载已完成的翻译并使用 pull 命令导入到项目中:

    $ phrase pull

可选项

  • 添加自定义区域下载目录到 i18n 加载路径

    如果将本地化文件下载到除 ./config/locales 之外的文件夹,请配置应用程序的 i18n 加载路径,以便新本地化文件可访问。

    打开 application.rbdevelopment/staging/production.rb 并添加配置(假设本地化文件下载到 ./custom/locales):

    config.i18n.load_path += Dir[Rails.root.join('custom', 'locales', '**', '*.yml').to_s]group :staging, :development do
      gem 'phraseapp-ruby'
    end

    重启应用程序后,新下载的文件可见。

  • 安装 phraseapp-ruby gem

    如果使用 API 编写自定义工作流,请使用 phraseapp-ruby gem。

    通过将其添加到 Gemfile,将 phraseapp-ruby gem 添加到您的应用程序:

    group :staging, :development do
      gem 'phraseapp-ruby'
    end

    使用 bundle 命令安装:

    $ bundle install

Ruby Motion 在 Strings 中

RubyMotion 是一个用于 iOS、OS X 和 Android 开发的工具链,可以用 Ruby 创建 iPhone、iPad、Mac 和 Android 应用。

phraseapp-rubymotion gem 将 RubyMotion 应用程序连接起来,以便从 国际化工作流 (iOS) 项目中受益。

安装 Gem

要安装 gem,请按照以下步骤操作:

  1. 使用 bundler 将 phraseapp-rubymotion gem 添加到您的项目:

    gem 'phraseapp-rubymotion'

    或手动:

    $ gem install phraseapp-rubymotion
  2. 在 Rakefile 中引入 gem。

初始化项目

将访问令牌和项目 ID 添加到应用程序 Rakefile:

Motion::Project::App.setup do |app|
  app.name = "测试应用程序"
  app.development do
    app.phraseapp do
      app.phraseapp.enabled = true
      app.phraseapp.access_token = "YOUR_ACCESS_TOKEN"
      app.phraseapp.project_id = "YOUR_PROJECT_ID"
    end
  end
end

项目的项目 ID 在项目设置中找到。

用法

使用 phraseapp-rubymotion gem 可以通过 API 自动发送新翻译,而无需将其写入 Localizable.strings 文件或上传。

本地化字符串

通过扩展它们与其本地化对应项来本地化所有字符串。在每个由 phraseapp-rubymotion 实现的字符串上调用 #__ 方法

"Hello World"

变为:

"Hello World".__

或者在使用后备翻译时:

"Hello World".__("我的后备翻译")

也可以使用通用密钥名称:

"HOME_WELCOME_BUTTON_LABEL".__
API通信

构建并运行应用程序(在模拟器中)。在开发模式下,phraseapp-rubymotion会自动发送所有本地化字符串,并被视为新创建的键。如果本地化文件正确放置,翻译也会被传输。

当翻译完成后,将它们与应用程序捆绑在一起。所有翻译可以通过API获取,并通过命令行客户端存储在RubyMotion项目中。

要获取翻译,请按照以下步骤操作:

  1. 安装命令行客户端(CLI)。

  2. 为项目配置CLI:

    $ phrase init

    完成配置项目的源和目标所需的步骤。选择字符串作为区域文件格式。

  3. 下载本地文件。

    一旦翻译完成,使用pull命令将数据下载回项目:

    $ phrase pull

    要将所有现有本地文件上传到项目:

    $ phrase push
这篇文章有帮助吗?

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.