- 浏览: 92510 次
- 性别:
- 来自: 香港
-
最新评论
-
ddddddddd:
忘记说谢谢了。谢谢您共享这个插件。帮了我大忙
Rails plugin: i18n -
ddddddddd:
我下载并使用了你的插件,感觉效果很好,不向其他同样功能的那样庞 ...
Rails plugin: i18n
An update from mod-i18n module. My first Ruby on Rails plugin. It is modified from Localization module. It do translation using YML based translation file, and choose language based on URL parameter.
Installation
script/plugin install source http://mod-i18n.googlecode.com/svn/trunk
1. Create Language File
Create a directory config/lang, under the directory, create yml files using the langugae name, e.g. config/lang/zh-HK.yml. In the file, it should contains string mapping, for example:
config/lang/zh-HK.yml: Listing contacts: 聯絡人列表 Show: 顯示 Edit: 修改 Delete: 移除
2. Edit Application String
In the application, replace content String to following format:
Source Code: 'blah' => ('blah') 'testing 5' => ('testing %d', 5) rhtml: <%= 'blah' %> => <%= 'blah' %> <%= 'testing 5' %> => <%= 'testing %d', 5 %>
3. Test the Applciation
Restart application. mod-i18n use post/get parameter 'lang' to determine the language (configurable through the constant PARAMETER_LANG in lib/i18n.rb).
Original URL: http://127.0.0.1/main/index URL for en-US: http://127.0.0.1/main/index?lang=en-US URL for zh-HK: http://127.0.0.1/main/index?lang=zh-HK
4. [OPTIONAL] Using Rails route
You may specify the language in URL. To do so, in config/route.rb, change the route to containing paramter 'lang'.
from: map.connect ':controller/:action/:id.:format' map.connect ':controller/:action/:id' to: map.connect ':lang/:controller/:action/:id.:format' map.connect ':lang/:controller/:action/:id' Original URL: http://127.0.0.1/main/index URL for en-US: http://127.0.0.1/en-US/main/index URL for zh-HK: http://127.0.0.1/zh-HK/main/index
评论
使用过程中发现一个小问题,yml文件分组会出错
error_message:
text_required:必填项目
date_invalid: 无效的日期
这种会显示不出来
我把i18n.rb第33行替换成了
while (translated.is_a?(Hash) && args.length > 0) translated = translated[args[0]] args.delete_at(0) end begin sprintf translated, *args rescue StandardError => e return translated end
用<%=_ "error_message", "text_required" %>就能够显示了
(我英文也写了一个yml文件)
发表评论
-
Code Geass CD入手
2007-08-23 14:12 1287終於入手了,Code Geass 的 OST2 和 モザイ ... -
Kaomoji (顔文字, emoticon) plugins for Rails
2007-08-23 16:15 1205Nothing big, just a little toy ... -
調查發現八達通易辦事轉賬系統一直有問題,涉款370萬元
2007-07-27 15:34 1240八達通承認易辦事7年扣錯錢 Via 明報即時新聞 早前,八達 ... -
Ruby on Rails plugin: QRCode
2007-07-23 14:42 1554I come across this page, a java ... -
[轉播] 呼籲:抵制7月25日明光社賣旗活動
2007-07-20 18:07 1199原文 @ 無神論者的巴別塔 慈善,只為幫助有需要的弱勢社群 ... -
Using AjaxMessaging to create a chatroom in 5 mins
2007-07-07 16:41 1273中文版: 用 AjaxMessaging 在五分鐘內造一個 c ... -
用 AjaxMessaging 在五分鐘內造一個 chat room
2007-07-07 17:03 1410English version: Using AjaxMess ... -
AjaxMessaging - bring realtime messaing to Ruby on Rails
2007-07-02 18:22 1421Proudly present my new plugins ... -
Eclipse 發表 Europa
2007-07-02 02:56 1131Eclipse Europa 是今年的 Eclipse 新版本 ... -
Ruby on Rails + AJAX + Mongrel + JMS/MQ/MOM = 即時通訊
2007-07-01 11:59 1606前文研究過利用 Flash XML ... -
更新: Ruby on Rails plugin i18n
2007-06-29 16:59 1321讀了 Takol 的 【ROR開發筆記】MultiLingua ... -
使用 Rails 和 Juggernaut 作即時通訊
2007-06-27 15:33 1613AJAX 在 AJAX 出現前,傳 ... -
全文搜尋 (Lucene 和 Ferret)
2007-05-20 17:45 1615搜尋器改變了人們的習慣。當有能力在互聯網上用 0.01 秒的搜 ... -
網摘 20070529 - 因為 Rails 放下其他事
2007-05-29 05:45 936網路與技術 RoR vs. PHP?談 web 開發技術的未 ... -
網摘 20070510
2007-05-10 06:01 998Web 微軟500億美元收購Yahoo!之傳言大拆解 - 與 ... -
Adobe 宣佈開放 Flex 的源碼
2007-04-27 03:43 1062重大消息:四月二十六日,Adobe 宣佈他們將會開放 Flex ... -
Defensive Design for the Web
2007-04-22 14:00 1083Defensive Design for the WebHo ... -
Aptana 繼 RadRails 後再宣佈和 RDT 合併
2007-04-21 16:10 1300Aptana 今天宣佈和 RDT 合併,該公司並會僱請 RDT ... -
20070416 網摘 - 知識+世代
2007-04-16 05:25 1049知識+世代 知識+型社會 - 當中學生只懂得使用 Yahoo ... -
Google 發表谷歌輸入法
2007-04-15 02:09 1362之前聽說Google 開放分析一萬億字所得的資料,但那只在英文 ...
相关推荐
名称 Mojolicious::Plugin::AdvancedMod - Mojolicious 的更多包子 版本 本文档涵盖 2014 年 1 月发布的 ... Rails 的类比:before_filter, after_filter 将请求参数转换为散列和多散列 加载 YAML/JSON 配置,封
我喜欢并尊重它的想法,但是我想使用I18n创建像一样简单的面包屑库。 安装 在您的Gemfile中 gem 'buoys' 并运行: $ bundle install 例子 首先生成配置和示例文件。 $ bin / rails g buoys : install create ...
10. **jsperanto**:基于EJS等模板引擎,支持复数形式、内插和混合查找,提供JSON字典,兼容多种浏览器,且类似Rails的I18N,但无需后端支持。 这些jQuery插件极大地简化了Web开发者的工作,使他们能够快速为网站...
主要特性:复数、插及其混合查找支持、使用 XHR 得到 JSON 字典、JSlinted,QUnited、类似 Rails 的 I18N,但是需要 sans 后台、没有全球化的、支持 IE6+,Firefox3+,Safari 3+, Chrome, Opera9 +、需要 jQuery1.3.2+...
7. **I18N(国际化)**:Jfina 提供了简单的国际化支持,开发者可以通过配置不同的语言包,实现多语言环境的应用。 8. **工具类(Util)**:Jfina 内置了一些常用的工具类,如DateUtil、StrUtil等,帮助开发者快速...