Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 126 lines (101 sloc) 4.715 kB
cf61270 @dylanz playing with the readme
authored
1 h1. A Database Backend For Rails I18N
2
2d93b5b @dylanz do a bit of clean up, and update README
authored
3 Stores your translations in the database, rather than yaml files. As you tag items with i18n.t() throughout your code base, all untranslated items are marked and added to the database. An admin panel is provided so translators can quickly translate untranslated text. All lookups occur in a cache store of your choice prior to hitting the database.
cf61270 @dylanz playing with the readme
authored
4
b7983cf updating README with Disclaimer!
Dylan Stamat authored
5 h2. DISCLAIMER!
6
949329f adding wlorentson's patch for nested hash lookups/returns
Dylan Stamat authored
7 * -In implementing this into another project, I realized that the currency support is currently broken. It basically boils down to the i18n gem accessing some of the Rails i18n yaml's in a different way than others. In this case, it's requesting a parent key, and expects a hash to be returned containing the children. This is not baked in the plugin at the moment, and any contributions toward this would be well received.- Thank you wlorentson!
07205da adding some disclaimers about the authorization of translations_contr…
Dylan Stamat authored
8
9 * The translations_controller is unprotected, and you'll probably want to add some kind of authorization filter to it to make sure the outside world can't access it.
cf61270 @dylanz playing with the readme
authored
10
11 h2. Installation
12
13 <pre>
14 <code>
6f4d776 Wrap I18nUtil.synchronize_translations with a rake task and add a rak…
Shane Mingins authored
15 script/generate i18n_backend_database # add migration
16 rake db:migrate # migrate
17
18 rake i18n:populate:load_default_locales # populate default locales
19 rake i18n:populate:from_rails # populate the locales and translations tables from all Rails Locale YAML files.
20 rake i18n:populate:from_application # populate the translation tables from translation calls within the application.
21 rake i18n:populate:synchronize_translations # create non-default locale translation records from default locale translations.
22 rake i18n:populate:all # run all populate tasks.
6165d31 Added rake task and code to support translating untranslated text usi…
Shane Mingins authored
23 rake i18n:translate:google # translate all untranslated string values using Google Language Translation API.
cf61270 @dylanz playing with the readme
authored
24 </code>
25 </pre>
26
27
28 In config/initialisers/i18n.rb
29
30 <pre>
31 <code>
32 I18n.backend = I18n::Backend::Database.new # registers the backend
33 I18n.backend.cache_store = :memory_store # optional: specify an alternate cache store
27e7dd1 Moves some rake task code to a util class so tests can load en.yml fi…
Shane Mingins authored
34 I18n.backend.localize_text_tag = '##' # optional: specify an alternate localize text tag, the default is ^^
cf61270 @dylanz playing with the readme
authored
35 </code>
36 </pre>
37
f08b1f9 Added the start of the admin panel. Pretty much used scaffold default…
Shane Mingins authored
38 In config/routes.rb to register admin panel routes
39
40 <pre>
41 <code>
42 map.from_plugin 'i18n_backend_database'
43 </code>
44 </pre>
27e7dd1 Moves some rake task code to a util class so tests can load en.yml fi…
Shane Mingins authored
45
580c198 Let's try that again!
Shane Mingins authored
46 h2. Use
27e7dd1 Moves some rake task code to a util class so tests can load en.yml fi…
Shane Mingins authored
47
580c198 Let's try that again!
Shane Mingins authored
48 All non-user generated text provided by the application needs to be wrapped in a call to I18n.t().
7787d2e Fix readme
Shane Mingins authored
49 <pre>
50 <code>
580c198 Let's try that again!
Shane Mingins authored
51 I18n.t("Hello there!")
7787d2e Fix readme
Shane Mingins authored
52 </code>
53 </pre>
580c198 Let's try that again!
Shane Mingins authored
54
55 Interpolation is handled by passing in key/value pairs as a value to an interpolation tag ( {{ }} ).
7787d2e Fix readme
Shane Mingins authored
56 <pre>
57 <code>
580c198 Let's try that again!
Shane Mingins authored
58 I18n.t("Hello there {{name}}!", :name => "Dylan")
7787d2e Fix readme
Shane Mingins authored
59 </code>
60 </pre><pre>
61 <code>
580c198 Let's try that again!
Shane Mingins authored
62 I18n.t("Click {{here}} or {{there}}", :here => "link_to(I18n.t('midnite'), croix_path)", :there => "link_to(I18n.t('staten_island'), wu_path)")
7787d2e Fix readme
Shane Mingins authored
63 </code>
64 </pre>
580c198 Let's try that again!
Shane Mingins authored
65
66 Pluralization is handled by passing in a "count" key value pair, which is a unique interpolation value.
7787d2e Fix readme
Shane Mingins authored
67 <pre>
68 <code>
580c198 Let's try that again!
Shane Mingins authored
69 I18n.t("You are {{count}} years old", :count => 100)
7787d2e Fix readme
Shane Mingins authored
70 </code>
71 </pre>
580c198 Let's try that again!
Shane Mingins authored
72
73 Links to external documents that need to be translated should be tagged as well.
7787d2e Fix readme
Shane Mingins authored
74 <pre>
75 <code>
580c198 Let's try that again!
Shane Mingins authored
76 I18n.t('http://www.elctech.com/core')
77 </code>
78 </pre>
27e7dd1 Moves some rake task code to a util class so tests can load en.yml fi…
Shane Mingins authored
79
580c198 Let's try that again!
Shane Mingins authored
80 All fragment cache view blocks need to have their keys prepended with the current locale.
7787d2e Fix readme
Shane Mingins authored
81 <pre>
82 <code>
580c198 Let's try that again!
Shane Mingins authored
83 cache("#{I18n.locale}-footer_#{controller.action_name}")
7787d2e Fix readme
Shane Mingins authored
84 </code>
85 </pre>
580c198 Let's try that again!
Shane Mingins authored
86
87 Date/Time localization is handled by using the I18n.l method. The format used will be :default (see next item for explanation).
7787d2e Fix readme
Shane Mingins authored
88 <pre>
89 <code>
580c198 Let's try that again!
Shane Mingins authored
90 I18n.l(@user.joined_at)
7787d2e Fix readme
Shane Mingins authored
91 </code>
92 </pre>
580c198 Let's try that again!
Shane Mingins authored
93
94 Date/Time localization can take a format parameter that corresponds to a key in the translations table (the Rails defaults :default, :short, and :long are available). We could in theory create our own like en.date.formats.espn_default.
7787d2e Fix readme
Shane Mingins authored
95 <pre>
96 <code>
580c198 Let's try that again!
Shane Mingins authored
97 I18n.l(@user.joined_at, :format => :default)
98 I18n.l(@user.joined_at, :format => :short)
99 I18n.l(@user.joined_at, :format => :espn_default)
7787d2e Fix readme
Shane Mingins authored
100 </code>
101 </pre>
580c198 Let's try that again!
Shane Mingins authored
102
87bb9fc Tidy up
Shane Mingins authored
103 Date/Time localization can take a custom format string as well.
7787d2e Fix readme
Shane Mingins authored
104 <pre>
105 <code>
580c198 Let's try that again!
Shane Mingins authored
106 I18n.l(@user.joined_at, :format => "%B %e, %Y")
7787d2e Fix readme
Shane Mingins authored
107 </code>
108 </pre>
580c198 Let's try that again!
Shane Mingins authored
109
110 Text stored in a database can be localized by tagging the text being stored and then localizing in the view etc.
7787d2e Fix readme
Shane Mingins authored
111 <pre>
112 <code>
580c198 Let's try that again!
Shane Mingins authored
113 I18n.tlt("is now friends with") => "^^is now friends with^^"
c3aeda4 Add space
Shane Mingins authored
114 I18n.lt("shane ^^is now friends with^^ dylan") => "shane ahora es con amigos dylan"
7787d2e Fix readme
Shane Mingins authored
115 </code>
116 </pre>
27e7dd1 Moves some rake task code to a util class so tests can load en.yml fi…
Shane Mingins authored
117
73f4c3d typo
Shane Mingins authored
118 Images can be translated with the I18n.ta tag
7ee2aa8 Added extra to README
Shane Mingins authored
119 <pre>
120 <code>
121 <%= image_tag(I18n.ta("logos/elc.gif"), :size => "134x75") %>
122 </code>
123 </pre>
124 In this example, for a locale es, there should be an image: public/es/images/logos/elc.gif
125
Something went wrong with that request. Please try again.