Hi Judith-
The following uses Swahili as a base_language US English as the default language and will give you a language picker using the native languages which gives it a cool look as the language fonts including CJK.
Let me know if you get stuck.
Best Regards-
Charles
in config/initializers/globalize.rb
include Globalize
Locale.set_base_language 'swa-SW' # Swahili is used to avoid messing up translations if we change a word in english
LOCALES = {
'en' => 'en-US',
'es' => 'es-MX',
'zh' => 'zh-CH'
}.freeze
DEFAULT_LOCALE = 'en-US'
DEFAULT_DATE_FORMAT = '%H:%M:%S - %A %B %d %Y'
# let rails handle international characters
$KCODE = 'u'
require 'jcode'
#########
in your application.rb
protected
def set_locale
# params overrides session, but en-US is only used if both
# params and session are absent
session[:locale] = LOCALES[params[:locale]] ||
session[:locale] ||
'en-US'
Locale.set session[:locale]
rescue
Locale.set DEFAULT_LOCALE
end
def set_charset
headers["Content-Type"] = "text/html; charset=utf-8" if headers["Content-Type"].blank?
end
####
somewhere in your layout views
<%= set_user_language %>
#########
and in your application_helper.rb
# Set the user language using the LOCALES from globalize.rb in config
# call by <%= set_user_language %>
#FIXME need to set locale.language_code for the test envirement
# added |code| link_to code.t, so that we can show Chinese character at the language bar. translate 'zh' at admin/translate)
def set_user_language
LOCALES.keys.map {|code| link_to code.t, url_for(:locale => code) }.join(" | ")
end
######
On Thu, May 15, 2008 at 1:32 PM, Dan Coutu <
coutu@...> wrote:
Judith, perhaps one thing that will help you out is to know that in fact the globalize translations table can use anything you like for a key. While all of the examples are complete English phrases it does not have to be used that way. You can readily use a shorthand encoding mechanism for each message and that will index (and therefore be looked up) much faster than long phrases.
Note: if you do this then you will have to add "translations" for the English text in addition to other languages. Then the "translated" English will show up in place of the "keyword" English text.
Dan
Judith Meyer wrote:
Hello,
I still haven't got an answer, even though I wrote to this list
several weeks ago. I want to let you know that I'm really worried
about scalability - I'm programming a really big social network and
I'm very worried about how this will scale, seeing that texts from the
views in the database are identified by the English texts rather than
an id or something more searchable. If nobody can reassure me or give
me an example of a really popular website that successfully uses
Globalize, I will do a major fork / re-write for my company. We just
can't risk having to re-code this when translations refuse to scale to
keep up with our growth of users.
Best regards,
Judith Meyer