Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

combined features and fixes currently in use by numerex for several production apps #15

Open
wants to merge 112 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
61abf2a
Initial approach for Rails 3 compatibility
sborrazas Oct 20, 2011
3f4bd01
Editing translations now works fine.
sborrazas Oct 20, 2011
ddf017c
Adding more changes for rails 3 compatibility
sborrazas Oct 21, 2011
0cecff8
Improvements
sborrazas Oct 21, 2011
d849ff3
Adding the yml to DB and DB to yml tasks
sborrazas Oct 24, 2011
c9c3b8c
When importing from the yml files, if a new locale is found it is ign…
sborrazas Oct 25, 2011
4bfa122
Removing all the unnecessary public stuff
sborrazas Oct 26, 2011
36884f3
Fixes for import task + including the translation model into I18n::Ba…
sborrazas Oct 26, 2011
2da6642
Translation class no longer inside Backend module
sborrazas Oct 27, 2011
2606c54
No longer using Simple Backend to load yaml files
sborrazas Nov 2, 2011
c083683
Added start of gem
Nov 16, 2011
30cf3f6
Added railstie
Nov 16, 2011
41a1f63
Clearing cache after importing translations
sborrazas Nov 16, 2011
47d3784
Updating documentation
sborrazas Nov 16, 2011
eaa7cb7
Improving documentation
sborrazas Nov 16, 2011
2578175
Improving documentation. Part 2
sborrazas Nov 16, 2011
74400da
Load correctly using Railtie
Dec 13, 2011
3bdb0b7
Added hack for transliterate
Dec 13, 2011
cf89ec3
Improving tests and documentation. Also fixing .one bug.
sborrazas Jan 2, 2012
de5b85c
Oops, fogot adding some files for previous commit
sborrazas Jan 2, 2012
dca60a4
merge w/ gem changes from joevandyk
spemmons Apr 27, 2012
2b25354
support rvm
spemmons Apr 27, 2012
8b91c9b
suppress errors in rake tasks
spemmons Apr 27, 2012
642fa8f
don't fail on bad translations
spemmons Apr 27, 2012
70f39b0
remove deprecated Railtie attribute
spemmons Apr 28, 2012
4024be5
make sure original format (which could be a constant) is not modified
spemmons May 19, 2012
460a6cc
add engine, but also some diagnostics in progress
spemmons May 20, 2012
61fdd15
add engine, but also some diagnostics in progress
spemmons May 20, 2012
7f9a28d
only use Engine, not Railtie, to avoid duplicate Rake task generation
spemmons May 20, 2012
cf3946f
capture TranslationSource when loading from YML files and elsewhere
spemmons May 20, 2012
7704d12
better "from_application" matching
spemmons May 21, 2012
2104b85
better "from_application" matching
spemmons May 21, 2012
01bde9a
Merge pull request #1 from spemmons/master
spemmons May 21, 2012
a3d67c2
allow for empty sections in a YAML file
spemmons May 21, 2012
9cdbddb
get import/export working so that it only includes sources that don't…
spemmons May 21, 2012
cdb51ca
don't create empty translations for non-default locales, let "synchro…
spemmons May 21, 2012
78f6691
make sure "blanks" are "nulls" and tweak VERBOSE logging
spemmons May 21, 2012
798fa9b
Merge pull request #2 from spemmons/master
spemmons May 21, 2012
777a1af
import all locales by default and look to the application as the sou…
spemmons May 21, 2012
c8b40ff
Merge pull request #3 from spemmons/master
spemmons May 21, 2012
d51e212
remove reference to :asset_translations -- where did this come from??
spemmons May 21, 2012
e1680e6
fixed bug where processing was in a "verbose?" line that doesn't alwa…
spemmons May 21, 2012
436f0d4
Merge pull request #4 from spemmons/master
spemmons May 21, 2012
6e2c0ef
reduce logging of warnings
spemmons May 22, 2012
76b584c
Merge pull request #5 from spemmons/master
spemmons May 22, 2012
5e1ab1d
don't require the key to be a Symbol in order to have a :scope
spemmons May 22, 2012
8a39a31
Merge pull request #6 from spemmons/master
spemmons May 22, 2012
7549987
introduce "Unsourced" selection to help manage "discovered" translations
spemmons May 23, 2012
e206c9b
Merge pull request #7 from spemmons/master
spemmons May 23, 2012
7154cdc
detect that a translation already exists when capturing from the appl…
spemmons May 23, 2012
cdca40f
Merge pull request #8 from spemmons/master
spemmons May 23, 2012
9c31b82
move toward Arel queries
spemmons May 26, 2012
a308b2b
check the RIGHT list of attributes for :source_id and load models usi…
spemmons May 28, 2012
1b48814
remove diagnostic "puts"
spemmons May 28, 2012
e2eff54
Merge pull request #9 from spemmons/master
spemmons May 28, 2012
5d7f58f
stop recursive evaluation of defaults and find the best option the fi…
spemmons May 29, 2012
57f0257
update an existing locale with a new name if it has changed (e.g., re…
spemmons Jun 13, 2012
b56204d
Merge pull request #10 from spemmons/master
spemmons Jun 13, 2012
7d42e15
add exclusion for synchronization
spemmons Jun 15, 2012
86fa43b
Merge pull request #11 from spemmons/master
spemmons Jun 15, 2012
a900902
Fixed generator to work with Rails3
borovsky Jun 19, 2012
66555ad
Merge pull request #12 from partizan/master
spemmons Jun 19, 2012
31a374f
Merge pull request #6 from partizan/master
spemmons Jun 19, 2012
00b68c4
changes to get rspec tests working -- WIP
spemmons Jun 20, 2012
bb3bc59
Merge branch 'master' of github.com:spemmons/i18n_backend_database
spemmons Jun 20, 2012
a60c0b7
move to a directory reflecting the module hierarchy -- rspec doesn't …
spemmons Jun 20, 2012
069d2f3
put back self. in front of up and down methods -- why were these remo…
spemmons Jun 20, 2012
e160884
reference the generator migration but with a numeric prefix so it can…
spemmons Jun 20, 2012
e7e7da3
use new :find_or_create! method on I18n::Backend::Locale
spemmons Jun 20, 2012
2a5510e
reverted some bad advice about the "memory" database name in sqlite3
spemmons Jun 20, 2012
5df375c
remove debug output
spemmons Jun 20, 2012
50ce195
backup an existing translations file in place
spemmons Jun 20, 2012
b5da1d1
Merge pull request #13 from spemmons/master
spemmons Jun 20, 2012
3727946
add exclusion patterns for I18n.load_path yml files that are not need…
spemmons Jun 21, 2012
c4ff5b7
Merge pull request #14 from spemmons/master
spemmons Jun 21, 2012
bfb0860
load yaml files for the default locale before others and only create …
spemmons Jun 23, 2012
259f5f7
display visual translation stats;
spemmons Jun 24, 2012
7df9514
add backup of all locales' unsourced translations
spemmons Jun 24, 2012
98654fa
only try to discover application translations when the first paramete…
spemmons Jun 24, 2012
1e66394
Merge pull request #15 from spemmons/master
spemmons Jun 24, 2012
681a879
allow turning the display of keys on/off and distinguish between miss…
spemmons Jul 1, 2012
dcf8415
Merge pull request #16 from spemmons/master
spemmons Jul 2, 2012
1f2cdea
revise pattern matching to explicitly check for "..." and '...' seque…
spemmons Aug 24, 2012
431670d
Merge pull request #17 from spemmons/master
spemmons Aug 24, 2012
4dff393
oops! handle starting directory properly
spemmons Aug 24, 2012
fe61e42
Merge pull request #18 from spemmons/master
spemmons Aug 24, 2012
295e026
include %(...) and %[...] as strings to be captured
spemmons Aug 24, 2012
5e270eb
Merge pull request #19 from spemmons/master
spemmons Aug 24, 2012
f359b0c
add csv export
spemmons Aug 26, 2012
ddac590
Merge pull request #20 from spemmons/master
spemmons Aug 26, 2012
dec1d26
explicitly reference I18n::Backend::Locale instead of simply Locale
spemmons Sep 19, 2012
eff6cdf
Merge pull request #21 from spemmons/master
spemmons Sep 19, 2012
9e61dc0
do not publish translation GUI in production
spemmons Sep 22, 2012
fc1e2af
Merge pull request #22 from spemmons/master
spemmons Sep 22, 2012
bd321da
fix bug in %[...] and %(...) matches for finding translated_objects
spemmons Sep 24, 2012
837fced
Merge pull request #23 from spemmons/master
spemmons Sep 24, 2012
876c5e4
detect the need for a new translation when raw key strings have multi…
spemmons Sep 24, 2012
6d3de5d
Merge pull request #24 from spemmons/master
spemmons Sep 24, 2012
59183b9
remove decode/encode functionality before parsing. UGPS-538
marceloeloelo Dec 7, 2012
dd50b19
Merge pull request #8 from numerex/ugps-538
spemmons Jan 9, 2013
5f3cce9
Fix for incompatible encoding error on UplinkGPS staging
Jan 16, 2013
128f75a
Merge pull request #9 from numerex/master
spemmons Jan 16, 2013
0354c49
revert change removing encode/decode handling -- it is now clear why …
spemmons Jan 16, 2013
c57ad09
fix for incompatible encoding error (ugps-574)
virginia-rodriguez Jan 25, 2013
a41b840
New Rails version: 3.2.12; add unique constraint to translation
Feb 13, 2013
8f98b6a
Remove unique constraint
Feb 14, 2013
b0515c7
Add logging after create
Feb 14, 2013
b30d625
Remove debugging.. move to another branch
Feb 15, 2013
bc25406
Merge pull request #10 from numerex/rails32
spemmons Feb 21, 2013
411ae6d
ensure that the locale exists before trying to create a translation
spemmons Feb 21, 2013
cadc875
address mass-assignment check
spemmons Mar 14, 2013
431be15
address mass-assignment check
spemmons Mar 14, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.idea/
.bundle/
log/*.log
pkg/
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--format=documentation
1 change: 1 addition & 0 deletions .rvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rvm use ruby-1.9.2@i18n --create
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"
gemspec

gem 'rails','3.2.12'
113 changes: 113 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
PATH
remote: .
specs:
i18n_backend_database (0.1.0)
rails (>= 3)

GEM
remote: http://rubygems.org/
specs:
actionmailer (3.2.12)
actionpack (= 3.2.12)
mail (~> 2.4.4)
actionpack (3.2.12)
activemodel (= 3.2.12)
activesupport (= 3.2.12)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
activemodel (3.2.12)
activesupport (= 3.2.12)
builder (~> 3.0.0)
activerecord (3.2.12)
activemodel (= 3.2.12)
activesupport (= 3.2.12)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activeresource (3.2.12)
activemodel (= 3.2.12)
activesupport (= 3.2.12)
activesupport (3.2.12)
i18n (~> 0.6)
multi_json (~> 1.0)
arel (3.0.2)
builder (3.0.4)
diff-lcs (1.1.3)
erubis (2.7.0)
hike (1.2.1)
i18n (0.6.1)
journey (1.0.4)
json (1.7.7)
mail (2.4.4)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.21)
multi_json (1.6.0)
polyglot (0.3.3)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.3)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.12)
actionmailer (= 3.2.12)
actionpack (= 3.2.12)
activerecord (= 3.2.12)
activeresource (= 3.2.12)
activesupport (= 3.2.12)
bundler (~> 1.0)
railties (= 3.2.12)
railties (3.2.12)
actionpack (= 3.2.12)
activesupport (= 3.2.12)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.0.3)
rdoc (3.12.1)
json (~> 1.4)
rspec (2.12.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
rspec-core (2.12.2)
rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.12.2)
rspec-rails (2.12.2)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 2.12.0)
rspec-expectations (~> 2.12.0)
rspec-mocks (~> 2.12.0)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.7)
thor (0.17.0)
tilt (1.3.3)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.35)

PLATFORMS
ruby

DEPENDENCIES
i18n_backend_database!
rails (= 3.2.12)
rspec (>= 2.0.0)
rspec-rails (>= 2.0.0)
sqlite3 (>= 1.3.4)
72 changes: 31 additions & 41 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,81 +1,72 @@
h1. A Database Backend For Rails I18N
h1. A Database Backend For Rails I18N (Now for rails 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.
Stores your translations in the database, rather than yaml files. As you tag items with 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.

h2. DISCLAIMER!

* -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!

* 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.

h2. Installation

<pre>
<code>
script/generate i18n_backend_database # add migration
rake db:migrate # migrate

rake i18n:populate:load_default_locales # populate default locales
rake i18n:populate:from_rails # populate the locales and translations tables from all Rails Locale YAML files.
rake i18n:populate:from_application # populate the translation tables from translation calls within the application.
rake i18n:populate:synchronize_translations # create non-default locale translation records from default locale translations.
rake i18n:populate:all # run all populate tasks.
rake i18n:translate:google # translate all untranslated string values using Google Language Translation API.
script/generate i18n_backend_database # add migration
rake db:migrate # migrate

rake i18n:populate:load_default_locales # populate default locales
rake i18n:populate:from_rails # populate the locales and translations tables from all Rails Locale YAML files.
rake i18n:populate:from_application # populate the translation tables from translation calls within the application.
rake i18n:populate:synchronize_translations # create non-default locale translation records from default locale translations.
rake i18n:populate:all # run all populate tasks.
rake i18n:translate:google # translate all untranslated string values using Google Language Translation API.

rake i18n:import_translations locale=<locale> # Import the translations from the translations/<locale>.yml
rake i18n:export_translations # Exports all the database translations to the translations/ folder
</code>
</pre>


In config/initialisers/i18n.rb

<pre>
<code>
I18n.backend = I18n::Backend::Database.new # registers the backend
I18n.backend.cache_store = :memory_store # optional: specify an alternate cache store
I18n.backend.localize_text_tag = '##' # optional: specify an alternate localize text tag, the default is ^^
</code>
</pre>

In config/routes.rb to register admin panel routes

<pre>
<code>
map.from_plugin 'i18n_backend_database'
</code>
</pre>

h2. Use

All non-user generated text provided by the application needs to be wrapped in a call to I18n.t().
<pre>
<code>
I18n.t("Hello there!")
t("Hello there!")
</code>
</pre>

Interpolation is handled by passing in key/value pairs as a value to an interpolation tag ( {{ }} ).
Interpolation is handled by passing in key/value pairs as a value to an interpolation tag ( %{ } ).
<pre>
<code>
I18n.t("Hello there {{name}}!", :name => "Dylan")
t("Hello there %{name}!", :name => "Dylan")
</code>
</pre><pre>
<code>
I18n.t("Click {{here}} or {{there}}", :here => "link_to(I18n.t('midnite'), croix_path)", :there => "link_to(I18n.t('staten_island'), wu_path)")
t("Click %{here} or %{there}", :here => "link_to(t('midnite'), croix_path)", :there => "link_to(t('staten_island'), wu_path)")
</code>
</pre>

Pluralization is handled by passing in a "count" key value pair, which is a unique interpolation value.
<pre>
<code>
I18n.t("You are {{count}} years old", :count => 100)
I18n.t("You are %{count} years old", :count => 100)
</code>
</pre>

Links to external documents that need to be translated should be tagged as well.
<pre>
<code>
I18n.t('http://www.elctech.com/core')
</code>
</pre>
t('http://www.elctech.com/core')
</code>
</pre>

All fragment cache view blocks need to have their keys prepended with the current locale.
<pre>
Expand All @@ -84,42 +75,41 @@ All fragment cache view blocks need to have their keys prepended with the curren
</code>
</pre>

Date/Time localization is handled by using the I18n.l method. The format used will be :default (see next item for explanation).
Date/Time localization is handled by using the localize (l) method. The format used will be :default (see next item for explanation).
<pre>
<code>
I18n.l(@user.joined_at)
l(@user.joined_at)
</code>
</pre>

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.
<pre>
<code>
I18n.l(@user.joined_at, :format => :default)
I18n.l(@user.joined_at, :format => :short)
I18n.l(@user.joined_at, :format => :espn_default)
l(@user.joined_at, :format => :default)
l(@user.joined_at, :format => :short)
l(@user.joined_at, :format => :espn_default)
</code>
</pre>

Date/Time localization can take a custom format string as well.
<pre>
<code>
I18n.l(@user.joined_at, :format => "%B %e, %Y")
l(@user.joined_at, :format => "%B %e, %Y")
</code>
</pre>

Text stored in a database can be localized by tagging the text being stored and then localizing in the view etc.
<pre>
<code>
I18n.tlt("is now friends with") => "^^is now friends with^^"
I18n.lt("shane ^^is now friends with^^ dylan") => "shane ahora es con amigos dylan"
tlt("is now friends with") => "^^is now friends with^^"
lt("shane ^^is now friends with^^ dylan") => "shane ahora es con amigos dylan"
</code>
</pre>

Images can be translated with the I18n.ta tag
<pre>
<code>
<%= image_tag(I18n.ta("logos/elc.gif"), :size => "134x75") %>
<%= image_tag(ta("logos/elc.gif"), :size => "134x75") %>
</code>
</pre>
In this example, for a locale es, there should be an image: public/es/images/logos/elc.gif

31 changes: 31 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'I18nBackendDatabase'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end



Bundler::GemHelper.install_tasks

require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new('spec')

task :default => :spec
Loading