这个网站wiki曾经给涂鸦的不成样子了
http://www.globalize-rails.org/
有时候可以正常的访问, 如有异常
可以访问Trac的
http://svn.globalize-rails.org/trac/globalize
或
http://wiki.globalize-rails.org/globalize/
先看看
globalize 教程
http://www.artweb-design.de/articles/2006/06/09/real-fun-get-on-rails-with-globalize
http://www.artweb-design.de/articles/2006/06/13/real-fun-get-on-rails-with-globalize-take-2
光说不练,天桥把式
Beast 汉化示范
安装禽兽不难, 看下面的步骤
http://www.olddognewtricks.co.uk/2006/09/beast.html
能行吗?
不行, 就一步一步地来吧
svn 你有吧, 看准了windows下2进制文件的---------安装方便点
http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=91
windows 平台用
http://subversion.tigris.org/files/documents/15/34093/svn-1.4.0-setup.exe
对小海龟的客户端, 没有就下, 图式界面适合初学者
http://tortoisesvn.tigris.org/
svn checkout http://svn.techno-weenie.net/projects/beast/trunk/
checkout 就像download一样下载代码到你的PC上了
rake freeze_edge
beast还没进化, 用的是Rails 1.2 版, 有安全漏洞的版哦
gem install RedCloth
装红布
database.yml 修改数据库的配置(用mysql的话,Mysql里建立个空的schema 名字与yml里的一样,注意用户密码,比如root, )
导入数据表
rake db:schema:load RAILS_ENV=production
把加密的salt盐值改了
PASSWORD_SALT 在 config/environment.rb
用ruby script/server -e production 启动
localhost:3000 IE 浏览器就看到了野兽,吼叫吧,现注册
可以开始Globalize啦
回顾前提条件
Beast(别的RoR程序也可以)已经安装部署好了, 可以运行。
检查确认数据库的设置 conf/database.yml
安装设置 Globalize
ruby script/plugin install http://svn.globalize-rails.org/svn/
globalize/globalize/branches/for-1.1
这个命令有问题,因为svn库里的路径有变化
可以svn 直接把/for-1.1 checkout 到vendor 路径下
命令如下
cd vendor/plugins
svn export svn://svn.globalize-rails.org/globalize/branches/for-1.1 --force
然后回到项目的根目录
下一步配置, 就是在创建翻译表, 留意你的数据库配置和服务在运行中
rake globalize:setup
报错
Mysql::Error: Identifier name
'index_globalize_translations_on_table_name_and_item_id_and_language_id'
is
too long: CREATE INDEX
`index_globalize_translations_on_table_name_and_item_id_and_language_id`
ON
globalize_translations (`table_name`, `item_id`, `language_id`)
类似
http://www.ruby-forum.com/topic/80049
Indentifier name too long
Posted by Dylan Stamat (Guest)
on 05.09.2006 09:57
(Received via mailing list)
Running Edge (4991) and MySQL (5.0.22)
==============================
When running "rake db:migrate"
Mysql::Error: Identifier name
'index_globalize_translations_on_table_name_and_item_id_and_language_id'
is
too long: CREATE INDEX
`index_globalize_translations_on_table_name_and_item_id_and_language_id`
ON
globalize_translations (`table_name`, `item_id`, `language_id`)
Re: Indentifier name too long
Posted by Martin Bernd Schmeil
on 05.09.2006 10:20
Just add a
:name => „something_idx“
parameter to the add_index statement.
Btw. If you have the same problem with foreign_keys:
1) create an index with a shorter name
2) add_fkey …, :name => “something_fk”, :index => false
does the trick.
Also you can handle the identifier name limit for the foreign key itself
and index with a possibly too long name will be auto created …unless you
use the :index => false option. On most (all?) RDBMS you need an index
for foreign keys column(s) though.
- Bernd
上面的介绍不详细, 从数据库里看到表的结构已经建立了,但没有数据,在创建index时候出了问题
cd db
cd migrate
044_globalize_migration.rb 打开有
找add_index的字段
按上面的Bernd方法,还是不行,提示index建立时出错,
把add_index屏蔽掉, 不是所有....哈
重新运行 rake globalize:setup
检查beast数据库里多了表和数据, Ok
下一步该Configuration
config/environment.rb 文件里加入下面的代码, 放在initial xxxx
end 的后面:
# Include your application configuration below include Globalize Locale.set_base_language 'en-US' LOCALES = {'pl' => 'pl-PL', 'en' => 'en-US', 'es' => 'es-ES', 'fr' => 'fr-FR'}.freeze
LOCALES = {'pl' => 'pl-PL',
'en' => 'en-US',
'es' => 'es-ES',
'fr' => 'fr-FR'}.freeze
可以做相应的修改,
LOCALES = {
'en' => 'en-US',
'zh' => 'zh-CN'
}.freeze
或直接用
Locale.set_base_language('en-US')
config/routes.rb 的文件也来点:
map.connect ':locale/:controller/:action/:id'
app/controllers/application.rb file:
class ApplicationController < ActionController::Base before_filter :set_locale def set_locale if !params[:locale].nil? && LOCALES.keys.include?(params[:locale]) Locale.set LOCALES[params[:locale]] else redirect_to params.merge( 'locale' => Locale.base_language.code ) end end end
如果再次启动webrick则 localhost:3000的指向为http://localhost:3000/en/forums
翻译静态的内容 static content.
生成个翻译的控制器
ruby script/generate controller admin/translate
修改控制器
class Admin::TranslateController < ApplicationController def index @view_translations = ViewTranslation.find(:all, :conditions => [ 'built_in IS NULL AND language_id = ?', Locale.language.id ], :order => 'text') end def translation_text @translation = ViewTranslation.find(params[:id]) render :text => @translation.text || "" end def set_translation_text @translation = ViewTranslation.find(params[:id]) previous = @translation.text @translation.text = params[:value] @translation.text = previous unless @translation.save render :partial => "translation_text", :object => @translation.text end end
创建 app/views/admin/translate/_translation_text.rhtml 局部页面, 里面用来 translation_text action.
引用
<%= translation_text || '[no translation]' %>
要翻译静态内容可以使用 in_place_editor helper帮助类(内置在Rails 1.1) , 记着加入下面的代码
<%= javascript_include_tag :defaults %>
到 layout file ( admin 部分)
比如 创建一个程序应用范围的
app/views/layouts/application.rhtml layout –
可以copy 大多数的生成的products.rhtml , 只改标题并加上 javascript tag 标签
下面接着创建
app/views/admin/translate/_translation_form.rhtml
partial 局部模板给the form 这个是用来提供翻译的.
<%= render :partial => 'translation_text', :object => tr.text %> <%= in_place_editor "tr_#{tr.id}", :url => { :action => :set_translation_text, :id => tr.id }, :load_text_url => url_for({ :action => :translation_text, :id => tr.id })%>
帮助类中添加 app/helpers/application_helper.rb file:
def base_language_only yield if Locale.base? end def not_base_language yield unless Locale.base? end
在 app/views/admin/translate, 建个 index.rhtml
<% base_language_only do -%><% end -%> <% not_base_language do -%>Please choose language for translation
<%= "Language: " + Locale.language.native_name %>
<% @view_translations.each do |tr| -%> <%= render :partial => 'translation_form', :locals => {:tr => tr}%> <% end -%><% end -%>
要知后事如何, 且听下回分解