`
bd7lx
  • 浏览: 196188 次
社区版块
存档分类
最新评论

gettext 汉化的*正规*正轨*而且还是简单的方法

阅读更多
道喜技术高强, 下面两篇看完了就明了

http://www.hhtong.com/blog1/articles/2006/05/15/rails20060514_i18n_gettext

关键的步骤是
引用

增加文件application.rb的代码,其中第四行和第十一行参数要调整。其目的在于,我们确定我们软件使用什么语言。在这个文件中,我们定义该软件项目文字区域(textdomain):i18n_gettext。这一点是很重要。它必须和后面谈到文件.po的文件名相同。

http://www.hhtong.com/blog1/articles/2006/05/15/tools20060514_use_poedit

比Globalize简洁易行



Download poedit最新版1.3.6的link
2006-10-30 03:36:

http://sourceforge.net/project/showfiles.php?group_id=27043&package_id=18746&release_id=459538



http://manuals.rubyonrails.com/read/chapter/105

有这么个笑话老鼠给猫挂铃铛, 敢挂是勇气, 要挂的太多了, 老鼠也不愿意干了

铃铛出在第六步, 手工要维护的括号太多了

引用
#
# 我们要把所有文件D:\works_rails\i18n_gettext\*\*.rb,D:\works_rails\i18n_gettext\*\*.rhtml 需要翻译的文字写成为规定格式为:
_('原文')
例如,我们修改文件D:\works_rails\i18n_gettext\app\views\admin\list.rhtml
_('Show')
原来的形式为
‘Show’

分享到:
评论
4 楼 歆渊 2006-11-03  
恰好我刚写完了一个基于Java的文字国际化产品, 现在正在写教程, 基本思想是通过变量的注释块来定义消息模板, 里面可以定义消息参数和写js动态脚本, 程序运行的时候通过调用Messager.format()来生成输出, 一个简单例子如下:

public class Quick
{

    /**
    * {name} was {age} {! age>1?"years":"year"} old in year {year}.
    * 
    * @arg name : name of the person
    * @arg age : his/her age in that year
    * @arg year = 2006 : the year
    * @usage This is a demo message declaiming one person's age in a past year.
    */
    @Msg
    protected static final String YEAR_AGE = "yr-age";

    /**
     * {! 
function r2(n)
\{
   return Math.round(n*100)/100;
\}
     * }Current Memory Usage: \n
     * \t Free: {! r2(java.lang.Runtime.getRuntime().freeMemory()/1024)} KB\n
     * \tTotal: {! r2(java.lang.Runtime.getRuntime().totalMemory()/1024/1024)} MB\n
     * \t  Max: {! r2(java.lang.Runtime.getRuntime().maxMemory()/1024/1024)} MB
     */
    @Msg
    protected final static String MEM = "mem-usage";

    /**
     * There {! num > 1 ? "are" : "is"} {! num <= 0 ? "no" : num} {!num > 1 ? "files" : "file"}. 
     * 
     * @arg num = 1 : the number of file(s).
     */
    @Msg
    protected final static String FILE = "number-of-files";

    /**
     * This is escaped text:\n
     * \t \{this-is-text-instead-of-arg}\n
     * \t \{! this-is-text-instead-of-expr }
     */
    @Msg
    protected final static String ESC = "escaped-text";

    public static void main(String[] args)
    {
        Messager msgr = Messager.get();

        System.out.println(msgr.format(YEAR_AGE, "name", "Peter", "year", 2006, "age", 26));

        System.out.println("------------------------------------------------");
        
        System.out.println(msgr.format(MEM));

        System.out.println("------------------------------------------------");
        
        System.out.println(msgr.format(FILE, "num", 0));
        System.out.println(msgr.format(FILE, "num", "0.5"));
        System.out.println(msgr.format(FILE, "num", "1"));
        System.out.println(msgr.format(FILE, "num", "1.5"));
        System.out.println(msgr.format(FILE, "num", 6));

        System.out.println("------------------------------------------------");
        
        System.out.println(msgr.format(ESC));
    }

}

编译的时候自动生成XML资源文件 Quick.msg.xml 如下:
<?xml version="1.0" encoding="UTF-8"?>
<java>
  <text>
    <escaped-text>
      <![CDATA[This is escaped text:
 	 \{this-is-text-instead-of-arg}
 	 \{! this-is-text-instead-of-expr }]]>
      <args />
      <defined>tutor.msg.Quick(Quick.java:54)</defined>
      <used>tutor.msg.Quick(Quick.java:54)</used>
    </escaped-text>
    <yr-age>
      <![CDATA[{name} was {age} {! age>1?"years":"year"} old in year {year}.]]>
      <args>
        <name>name of the person</name>
        <age>his/her age in that year</age>
        <year default-value="2006">the year</year>
      </args>
      <usage>
        This is a demo message declaiming one person's age in a past year.
      </usage>
      <defined>tutor.msg.Quick(Quick.java:24)</defined>
      <used>tutor.msg.Quick(Quick.java:24)</used>
    </yr-age>
    <mem-usage>
      <![CDATA[{! function r2(n) \{ return Math.round(n*100)/100; \} }Current Memory Usage: 
 	 Free: {! r2(java.lang.Runtime.getRuntime().freeMemory()/1024)} KB
 	Total: {! r2(java.lang.Runtime.getRuntime().totalMemory()/1024/1024)} MB
 	  Max: {! r2(java.lang.Runtime.getRuntime().maxMemory()/1024/1024)} MB]]>
      <args />
      <defined>tutor.msg.Quick(Quick.java:38)</defined>
      <used>tutor.msg.Quick(Quick.java:38)</used>
    </mem-usage>
    <number-of-files>
      <![CDATA[There {! num > 1 ? "are" : "is"} {! num <= 0 ? "no" : num} {!num > 1 ? "files" : "file"}.]]>
      <args>
        <num default-value="1">the number of file(s).</num>
      </args>
      <defined>tutor.msg.Quick(Quick.java:46)</defined>
      <used>tutor.msg.Quick(Quick.java:46)</used>
    </number-of-files>
  </text>
</java>

然后翻译成中文的XML资源 Quick_zh.msg.xml 如下:
<?xml version="1.0" encoding="UTF-8"?>
<java>
  <text>
    <number-of-files>
      <![CDATA[有{num}个文件.]]>
      <args>
        <num default-value="1">the number of file(s).</num>
      </args>
    </number-of-files>
    <mem-usage>
      <![CDATA[{! function r2(n) \{ return Math.round(n*100)/100; \} }当前内存使用情况: 
 	 空闲: {! r2(java.lang.Runtime.getRuntime().freeMemory()/1024)} KB
 	 总数: {! r2(java.lang.Runtime.getRuntime().totalMemory()/1024/1024)} MB
 	 限制: {! r2(java.lang.Runtime.getRuntime().maxMemory()/1024/1024)} MB]]>
      <args />
    </mem-usage>
    <yr-age>
      <![CDATA[{year} 年的时候, {name} {age} 岁.]]>
      <args>
        <name>name of the person</name>
        <age>his/her age in that year</age>
        <year default-value="2006">the year</year>
      </args>
      <usage>
        This is a demo message declaiming one person's age in a past year.
      </usage>
    </yr-age>
    <escaped-text>
      <![CDATA[以下文字是经过转义的:
 	 \{这不是参数,而是文字}
 	 \{! 这不是表达式,而是文字 }]]>
      <args />
    </escaped-text>
  </text>
</java>

3 楼 bd7lx 2006-11-03  


是的

本贴使用的通俗说法汉化,打算就一个已有的程序,翻译成中文的界面的过程

还在试验其它的方法

http://wiki.rubyonrails.org/rails/pages/InternationalizationComparison

有体验的可以讲解一番

http://www.trikr.net/

这个原创的网站就是用Globalize 作的双语支持

2 楼 cookoo 2006-11-03  
gettext只解决文字的多语言版本问题,globalize还解决日期,货币,度量格式的国际化问题。
1 楼 bd7lx 2006-11-02  
算是给

http://www.iteye.com/topic/29540

接上个小尾巴

还有相关的汉化思考慢慢来

欢迎讨论,汉化的技术

相关推荐

Global site tag (gtag.js) - Google Analytics