openSUSE:WebYaST 国际化

跳转到:导航搜索

国际化

WebYaST 使用 ruby gettext 来管理翻译。关于 gettext 与 ruby/rails 结合使用的总体概述可以在这个 教程 中找到。

关于如何管理 po、mo 和 pot 文件的描述可以在 这里 找到。

这里是一个简短的总结

标记文本以便翻译

初始化 gettext 并设置控制器中的文本以便翻译

class MyPluginController < ApplicationController
  before_filter :login_required
  layout "main"
  # Initialize GetText and Content-Type to use yast_webclient_my_plugin.mo
  init_gettext "yast_webclient_my_plugin"  

  def index
    puts _("This text will be translated")
  end
end

在视图中设置文本以便翻译

<html>
<head>
  <title><%= _("This text will be translated") %></title>
</head>
<h2><%=_("This text will be also translated.")%></h2>
</html>

“#{name}” 样式不受支持。请使用 % 样式代替。

_("it's #{name}") => _("it's %s") % name
                  => _("it's %{name}") % {:name => name}

po、mo 和 pot 文件的位置

开发

---web-client
     |
     +---pot
     |   (location of all generated pot-files)
     |
     +---plugins
     |      |
     |      +---<plugin-name>
     |              |
     |              +---po
     |              |   (location of translations)
     |              |
     |              +---locale
     |                  (location of all mo-files)
     |
     +---webclient
            |
            +---po
            |   (location of all webclient core translations)
            |
            +---locale
            |   (location of all webclient core mo-files)
            |
            +---public
                  |
                  +---vendor (This directory will be NOT packaged for RPM)
                         |
                         +---text
                               |
                               +---locale
                                   (location of all plugin mo files)

已安装的 RPM

srv
 |
 +---www
      |
      +---yast
           |
           +---po
           |   (location of all webclient core translations)
           |
           +---locale
           |   (location of all webclient core mo-files)
           |
           +---vendor
                 |
                 +---plugins
                        |
                        +---<plugin-name>
                                 |
                                 +---po
                                 |  (location of plugin translations)
                                 | 
                                 +---locale
                                    (location of plugin mo-files)
  

/srv/www/yast/locale/

创建 POT 文件

运行 "updatepot" 任务以使用 updatepot 任务创建 pot 文件。

对于所有模块

web-client> rake updatepot

仅对于单个插件

web-client> cd plugins/plugin_foo
web-client/plugins/plugin_foo> rake updatepot

在两种情况下,pot 文件都将生成在

web-client/pot

这些文件必须发送给翻译人员。

管理 po 文件

po 文件将由翻译人员生成。为每种语言生成一个 po 文件。只需将 po 文件复制到相应的 po 目录中,通过创建语言子目录即可。

  ---po
      |
      +---en/yast2_webclient_<plugin-name>.po
      +---de/yast2_webclient_<plugin-name>.po
      +---fr/yast2_webclient_<plugin-name>.po
      +---fr_CH/yast2_webclient_<plugin-name>.po
      +---ja/yast2_webclient_<plugin-name>.po
      +...
      +..
      +.

您还可以使用 rake 命令

rake fetch_po <directory from which the po files have to be copied>

将所有 po 文件复制到正确的目录。

更新 po 文件后,您必须调用 rake makemo,如下一章所述。

创建 mo 文件

运行 "makemo" 任务以使用 makemo 任务创建 mo 文件。

对于所有模块

web-client> rake makemo

仅对于单个插件

web-client> cd plugins/plugin_foo
web-client/plugins/plugin_foo> rake makemo

它将在相应的 locale/ 目录中生成 mo 文件。

不要忘记重启 Web 服务器。