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

Don't execute save on files which actually aren't changed #125

Closed
jmuheim opened this issue Jan 25, 2015 · 6 comments
Closed

Don't execute save on files which actually aren't changed #125

jmuheim opened this issue Jan 25, 2015 · 6 comments

Comments

@jmuheim
Copy link

jmuheim commented Jan 25, 2015

I'd love to automatically do an i18n-tasks add-missing -v 'TRANSLATE: %{value}' whenever I add a new key in a view.

One approach for this is to use Guard Shell, which can execute a shell command automatically when file modifications are detected:

guard :shell do
  watch %r{app/\w+/(.+\.(html|rb)).*} do |m|
    `i18n-tasks add-missing -v 'TRANSLATE: %{value}'`
  end
end

This works pretty well, but the downside at the moment is, that the i18n-tasks add-missing command seems to save all yml files after inspecting them, also when the file doesn't change. This makes Guard get many new "files modified" signals: one for each yml file.

Here is the output of Guard:

Frame number: 0/1
[1] guard(main)> 12:42:36 - INFO - Browser connected.
12:42:44 - INFO - Reloading browser: app/views/layouts/application.html.slim

Added 1 keys
+--------+-----------------------------+------------------------+
| Locale | Key                         | Value                  |
+--------+-----------------------------+------------------------+
|   de   | layouts.application.hallo2d | TRANSLATE: TRANSLATE:  |
+--------+-----------------------------+------------------------+

Frame number: 0/1
12:42:46 - INFO - Reloading browser: config/locales/de.yml config/locales/layouts/de.yml config/locales/actions/de.yml config/locales/activerecord/de.yml config/locales/devise/de.yml config/locales/enumerize/de.yml config/locales/errors/de.yml config/locales/flash/de.yml config/locales/simple_form/de.yml config/locales/validates_timeliness/de.yml

Is there a reason why i18n-tasks does a "save" action to all yml files? Can it be disabled?

@glebm
Copy link
Owner

glebm commented Jan 25, 2015

i18n-tasks loads all of the data, manipulates it in memory, and then saves all of the data according to the routing config. One way to avoid this would be to compare the tree to the file before writing it in here.

glebm added a commit that referenced this issue Jan 25, 2015
@glebm
Copy link
Owner

glebm commented Jan 25, 2015

Does the commit above fix the issue?

@jmuheim
Copy link
Author

jmuheim commented Jan 25, 2015

No, it doesn't seem to:

14:59:28 - INFO - Reloading browser: app/views/layouts/application.html.slim

Added 1 keys
+--------+--------------------------+------------------------+
| Locale | Key                      | Value                  |
+--------+--------------------------+------------------------+
|   de   | layouts.application.asdf | TRANSLATE: TRANSLATE:  |
+--------+--------------------------+------------------------+

Frame number: 0/1
14:59:31 - INFO - Reloading browser: config/locales/de.yml config/locales/actions/de.yml config/locales/activerecord/de.yml config/locales/enumerize/de.yml config/locales/layouts/de.yml config/locales/devise/de.yml config/locales/flash/de.yml config/locales/errors/de.yml config/locales/simple_form/de.yml config/locales/validates_timeliness/de.yml

I specified the commit in the Gemfile like this:

gem 'i18n-tasks', github: 'glebm/i18n-tasks', ref: '050bea56177ccb2b31a790df60e85c1d53c55d0e'

@jmuheim
Copy link
Author

jmuheim commented Jan 25, 2015

By the way, when a key is added, it still seems to save all the files, but when none is added, no file is saved. Does this help?

Frame number: 0/1
15:02:29 - INFO - Reloading browser: app/views/layouts/application.html.slim

Added 1 keys
+--------+--------------------------+------------------------+
| Locale | Key                      | Value                  |
+--------+--------------------------+------------------------+
|   de   | layouts.application.asdf | TRANSLATE: TRANSLATE:  |
+--------+--------------------------+------------------------+

Frame number: 0/1
15:02:32 - INFO - Reloading browser: config/locales/de.yml config/locales/layouts/de.yml config/locales/actions/de.yml config/locales/activerecord/de.yml config/locales/devise/de.yml config/locales/enumerize/de.yml config/locales/errors/de.yml config/locales/flash/de.yml config/locales/simple_form/de.yml config/locales/validates_timeliness/de.yml

Frame number: 0/1
15:02:36 - INFO - Reloading browser: app/views/layouts/application.html.slim

Added 0 keys
ø

Frame number: 0/1

glebm added a commit that referenced this issue Jan 25, 2015
@glebm
Copy link
Owner

glebm commented Jan 25, 2015

How about now (be2b068)? Another option would be to load the file as a tree and compare the trees, but this should work as well.

@jmuheim
Copy link
Author

jmuheim commented Jan 25, 2015

Perfect! It's working. Thank you.

@jmuheim jmuheim closed this as completed Jan 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants