balinterdi / i15r Goto Github PK
View Code? Open in Web Editor NEWReplaces plain text strings in your views and replaces them with I18n message strings so you only have to provide the translations (i15r = internationalizer)
License: MIT License
Replaces plain text strings in your views and replaces them with I18n message strings so you only have to provide the translations (i15r = internationalizer)
License: MIT License
That is app/views
i15r produced:
- %span.num 12 - Notifications + %span.num= I18n.t("shared.notifications_button.notifications_button.12", :default => "12") + = I18n.t("shared.notifications_button.notifications_button.notifications", :default => "Notifications")
Internationalization of the number 12 is not wanted.
Nice gem, thanks. Unfortunatly I cannot use it on my haml views. Here is the output (partial) of a dry run:
- %p
- %h2 Resend unlock instructions
- %i (we need your current password to confirm your changes)
%i I18n.t("devise.registrations.edit.(we_need_your_current_password_to_confirm_your_changes)")
The %tags are removed & included in the translation. Some invalid chars are not escaped.
Cheers,
Jej
Hi,
I just ran i15r on an inherited project, and it runs mostly fine. Thanks for the good work!
However, I'm not sure of why would I want to run a tool that doesn't generate any yml file.
--no-default
, I get e.g. 1000 entries like I18n.t("users.new.name", :default => 'Name')
, and I still will have to manually create 1000 entries in en.yml. Even if I do that, then I'd have to manually remove (default: 'foo'
) from each t
call, for ensuring DRY/correctness.--no-default
, any app will become empty/broken until you manually create 1000 entries in en.yml.Either option is undesirable. As I see it, this gem would be only be useful if it generates a yml file as well.
Probably overwriting en.yml would be obstrusive/error-prone. However, generating a separate yml file could allow the developer to adapt it as he wishes.
Do you think you can make this happen?
For now I will be giving it a try, in my fork.
Cheers - Victor
Add an option/cli flag for adding the extracted string as a default option.
Turn
<h1>Hello</h1>
into
<h1><%= I18N.t ('posts.index.hello', :default => 'Hello') %></h1>
That would make it a lot easier to test and tailor to diff. needs.
Lines like the following ones (taken from scaffolded Rails artefacts) aren't properly replaced when running 'i15r .' from a Rails app root directory:
Controller 'create' action:
format.html { redirect_to @Company, notice: 'Company was successfully created.' }
Controller 'update' action:
format.html { redirect_to @Company, notice: 'Company was successfully updated.' }
index.html.erb view:
<%= link_to I18n.t("companies.index.destroy"), company, method: :delete, data: { confirm: 'Are you sure?' } %>
Hello,
Launching i15r (with the dry run option), I got the following error:
/Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/gems/i15r-0.5.3/lib/i15r/pattern_matcher.rb:44:in split': invalid byte sequence in US-ASCII (ArgumentError) from /Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/gems/i15r-0.5.3/lib/i15r/pattern_matcher.rb:44:in
run'
from /Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/gems/i15r-0.5.3/lib/i15r.rb:84:in sub_plain_strings' from /Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/gems/i15r-0.5.3/lib/i15r.rb:77:in
internationalize_file'
from /Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/gems/i15r-0.5.3/lib/i15r.rb:94:in block in internationalize!' from /Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/gems/i15r-0.5.3/lib/i15r.rb:94:in
each'
from /Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/gems/i15r-0.5.3/lib/i15r.rb:94:in internationalize!' from /Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/gems/i15r-0.5.3/bin/i15r:53:in
<top (required)>'
from /Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/bin/i15r:23:in load' from /Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/bin/i15r:23:in
eval' from /Users/jorisvh/.rvm/gems/ruby-2.0.0-p576/bin/ruby_executable_hooks:15:in
'
The issue was that I left a comment in French in my code (with the é letter), so it was not even due to some hardcoded string to replace. It could be really great to use i15r with full UTF-8 support.
Thank you and keep up the good work !
Joris
Hello, thanks for the gem. But sometimes it is converting the method names of the js code in html.erb to translation keys.
During tests: do nothing.
When dry-run option is given: output the content that would be written.
Unknown why i15r had issues with this line. Maybe it's because of the custom form generator we're using that provides a :label attribute? A very interesting failure mode.
-<%= f.text_field :feature_list, :size=>60, :label=>'Feature flags', :append=>' (space separated)', :help=>"Known: #{@features.join(', ')}" %>
+<%= f.text_field :feature_list, :size=>60, :label=>I18n.t("admin.accounts.form.feature_flags_append=>space_separated_help=>known{@featuresjoin_", :default => 'Feature flags', :append=>' (space separated)', :help=>"Known: #{@features.join(', '))}" %>
-<%= f.text_field :account_id, :label=>'Account ID', :size=>12, :readonly=>true, :clear=>false %>
+<%= f.text_field :account_id, :label=>'Account ID', I18n.t("admin.guests.form.size", :default => "size")=>12, :readonly=>true, :clear=>false %>
-<%= f.text_field :cluster_name, :label=>'Location', :size=>12, :readonly=>true %>
+<%= f.text_field :cluster_name, :label=>'Location', I18n.t("admin.guests.form.size", :default => "size")=>12, :readonly=>true %>
Hi Balint! How are you?
I'm using your gem and it works fine, congratulations!
I'd like to suggest a new feature that would save still more time: when replacements in views are generated, it could also generate a list of keys to translate.
Example:
<label for="user-name"><%= I18n.t("my_project.name") %></label>
<input type="text" id="user-name" name="user[name]" />
<label for="user-age"><%= I18n.t("my_project.age") %></label>
<input type="text" id="user-age" name="user[age]" />
would generate:
my_project:
name: name
age: age
Thanks for your work.
This one is rather big because we have to make sure that:
"Register (türkçe)" should become I18n.t("cool.register_türkçe") and not I18n.t("cool.register_(türkçe)")
They do pass in ruby1.9 but I am not sure they really get properly replaced. Insert spec snippets in test file and see. Also, try to make it work for Ruby1.8.
Currently it generates something like this:
en:
tickets:
_book_info:
book_info: BOOK INFO
Probably just removing the underscore is ok.
This can be elegantly done by injecting an OutputWriter to the I15R object.
Awesome gem. I've found myself wanting this gem, and now I have the gem, wanting this feature.
Ideally the config/locales/en.yml would just get populated with the discovered strings instead of them getting optionally hardcoded as defaults in the views.
I had a look at the code, and realised it wouldn't be easy to do cleanly without a bit of a refactor.
I think it would suit the visitor pattern: http://blog.bigbinary.com/2013/07/07/visitor-pattern-and-double-dispatch.html
Here's a sketch of the beginnings of it:
https://gist.github.com/markburns/7182190
If this is something you think the gem can/should do, then I'd like to give a crack at a PR.
Whenever a new page (view) is created, you can just write the texts in English and then run i15r new_view
to convert them to i18n strings.
$ i15r /path/to/app/views/shared/_my_account.html.slim -n
Running in dry-run mode
/path/to/app/views/shared/_my_account.html.slim:
/home/adrianov/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i15r-0.5.5/lib/i15r/pattern_matcher.rb:36:in `const_get': uninitialized constant SlimTransformer (NameError)
from /home/adrianov/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i15r-0.5.5/lib/i15r/pattern_matcher.rb:36:in `initialize'
from /home/adrianov/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i15r-0.5.5/lib/i15r.rb:84:in `new'
from /home/adrianov/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i15r-0.5.5/lib/i15r.rb:84:in `sub_plain_strings'
from /home/adrianov/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i15r-0.5.5/lib/i15r.rb:79:in `internationalize_file'
from /home/adrianov/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i15r-0.5.5/lib/i15r.rb:99:in `block in internationalize!'
from /home/adrianov/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i15r-0.5.5/lib/i15r.rb:99:in `each'
from /home/adrianov/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i15r-0.5.5/lib/i15r.rb:99:in `internationalize!'
from /home/adrianov/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/i15r-0.5.5/bin/i15r:56:in `<top (required)>'
from /home/adrianov/.rbenv/versions/2.2.3/bin/i15r:23:in `load'
from /home/adrianov/.rbenv/versions/2.2.3/bin/i15r:23:in `<main>'
I have an application using https://github.com/kevgo/sections_rails. Trying to run i15r app/sections
produces:
/home/rvm/.rvm/gems/ruby-2.0.0-p0/gems/i15r-0.5.1/lib/i15r.rb:43:in `file_path_to_message_prefix': No app. subfolders were found to determine prefix. Path is /home/rvm/apps/foo/app/sections/foo/edit/_edit.html.haml (I15R::AppFolderNotFound) from /home/rvm/.rvm/gems/ruby-2.0.0-p0/gems/i15r-0.5.1/lib/i15r.rb:60:in `internationalize_file' from /home/rvm/.rvm/gems/ruby-2.0.0-p0/gems/i15r-0.5.1/lib/i15r.rb:80:in `block in internationalize!' from /home/rvm/.rvm/gems/ruby-2.0.0-p0/gems/i15r-0.5.1/lib/i15r.rb:80:in `each' from /home/rvm/.rvm/gems/ruby-2.0.0-p0/gems/i15r-0.5.1/lib/i15r.rb:80:in `internationalize!' from /home/rvm/.rvm/gems/ruby-2.0.0-p0/gems/i15r-0.5.1/bin/i15r:46:in `' from /home/rvm/.rvm/gems/ruby-2.0.0-p0/bin/i15r:23:in `load' from /home/rvm/.rvm/gems/ruby-2.0.0-p0/bin/i15r:23:in `' from /home/rvm/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `eval' from /home/rvm/.rvm/gems/ruby-2.0.0-p0/bin/ruby_noexec_wrapper:14:in `'
There should be either a way for me to specify what the app root is, or i15r should determine that by itself, perhaps by traversing the tree up until it finds an "app" directory.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.