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

fixes #8874 - rework POT/PO updates for gettext 3's edit.po #2096

Closed
wants to merge 1 commit into from

Conversation

domcleal
Copy link
Contributor

3.1.13 adds an intermediate .edit.po file alongside each .po, which is meant
to be kept outside of SCM and updated by users, whereupon it's merged back into
the .po on the next rake gettext:find execution.

Previously we overwrote all gettext .po file changes with files directly from
Transifex, but now these are downloaded to .edit.po and gettext merges them
back in. Fuzzy merges have been disabled as they were inaccurate.


Reminder, use make -C locale tx-update to trigger it all.

Note there are a couple of style changes in the POT file, but I think they're good. 1) "TRANSLATORS" is now showing up in the comments, 2) source locations are enabled, 3) the header is in template form.

More details on the ticket comments too.

tx pull -f
-git commit -a -m "i18n - extracting new, updating rails, pulling from tx"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intentional? I think it is fine to have one less commit, I agree.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was intentional. The old way used to result in one commit as it would amend this original commit later. It used to do this early commit because it would then revert .po file changes back.

@lzap
Copy link
Member

lzap commented Jan 21, 2015

Nice, I am going to test this with core and than with discovery.

@domcleal
Copy link
Contributor Author

Thanks, I suspect we'll need to update .gitignore in plugins too.

@domcleal
Copy link
Contributor Author

Oh, and .tx/config. I wonder what else..

@lzap
Copy link
Member

lzap commented Jan 22, 2015

Makefiles obviously... testing now.

@lzap
Copy link
Member

lzap commented Jan 22, 2015

Hmmm I am not sure why actually make -C locale target works, but it does. I don't see this target. It should be all-mo which is the default one. Do you happen to know why it does work? Maybe locale stands for the directory name calling the default one.

@@ -4,7 +4,7 @@
gem 'rubocop', '0.26.1'

# for generating i18n files
gem 'gettext', '~> 3.1', :require => false
gem 'gettext', '>= 3.1.3', '< 4.0.0', :require => false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remind me why do we repeat it here once again? Time to zap it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

development.rb is the correct location, assets.rb is the duplicate. It has a comment above explaining, but it's a missing dependency in gettext_i18n_rails_js on gettext, so if somebody didn't have the development group, they'd need the gettext dep too.

@domcleal
Copy link
Contributor Author

I'm not sure I understand your comment about the target. The full command to extract & update translations is make -C locale tx-update. -C locale is the directory, tx-update is the target.

@lzap
Copy link
Member

lzap commented Jan 22, 2015

Oh yeah I missed the -C because I was calling it from locale/. Disregard :-)

Can you test/elaborate this patch? For me it does not create files named foreman_discovery.po anymore, but it names it just foreman.po for a plugin which was wrong when I was doing:

rake plugin:gettext[foreman_discovery]

Also I still see fuzzy messages added when doing this.

diff --git a/lib/tasks/gettext.rake b/lib/tasks/gettext.rake
index 676c461..abcb30a 100644
--- a/lib/tasks/gettext.rake
+++ b/lib/tasks/gettext.rake
@@ -22,7 +22,8 @@ begin
   desc 'Extract plugin strings - called via rake plugin:gettext[plugin_name]'
   task 'plugin:gettext', :engine do |t, args|

-    @engine = "#{args[:engine].camelize}::Engine".constantize
+    @domain = args[:engine]
+    @engine = "#{@domain.camelize}::Engine".constantize
     @engine_root = @engine.root

     namespace :gettext do
@@ -35,10 +36,13 @@ begin
         Dir.glob("#{@engine.root}/{app,db,lib,config,locale}/**/*.{rb,erb,haml,slim,rhtml,js}")
       end

+      def text_domain
+        @domain
+      end
+
     end

-    Foreman::Gettext::Support.add_text_domain args[:engine], "#{@engine_root}/locale"
-    ENV['TEXTDOMAIN'] = args[:engine]
+    Foreman::Gettext::Support.add_text_domain @domain, "#{@engine_root}/locale"

     Rake::Task['gettext:find'].invoke

# Keep TRANSLATORS comments
Rails.application.config.gettext_i18n_rails.xgettext = %w[--add-comments=TRANSLATORS:]
# Disable fuzzy .po merging
Rails.application.config.gettext_i18n_rails.msgmerge = %w[--no-fuzzy-matching]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need those settings for plugins too. Are you able to add it somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll test plugins, but since it's in Foreman's initialiser, I'd have thought they'd inherit it naturally?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd expect that, but this is what I get for discovery:

 msgstr ""
 "Project-Id-Version: foreman_discovery 2.0.0.rc1\n"
 "Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2014-08-20 08:33+0100\n"
 "PO-Revision-Date: 2014-09-16 16:47+0000\n"
 "Last-Translator: Ettore Atalan <atalanttore@googlemail.com>\n"
-"Language-Team: German (http://www.transifex.com/projects/p/foreman/language/de/)\n"
+"Language-Team: German (http://www.transifex.com/projects/p/foreman/language/de"
+"/)\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
@@ -36,15 +36,33 @@ msgstr "Standort zuweisen"
 msgid "Assign Organization"
 msgstr "Organisation zuweisen"

+#, fuzzy
+msgid "Auto Provision"
+msgstr "Bereitstellen"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this has no effect on one of the two merges, as the merge from .edit.po to .po isn't configurable. I filed ruby-gettext/gettext#44 to have the options apply to both.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gettext 3.2.1 fixes the issue, I've updated the minimum dependency to get the fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the concern here? The presence of this +#, fuzzy line? I still get it in foreman_remote_execution when using this PR and gettext 3.2.1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just that we don't intend to use fuzzy translation matching. Can you provide the specifics of what string and translation is in each file as you extract, pull and merge?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you provide the specifics of what string and translation is in each file as you extract, pull and merge?

What do you need? There aren't any translations yet for REX.

I followed the wiki page, incorporated the changes from theforeman/foreman_plugin_template#13, and ran the rake task. I'm not sure what I need to do to verify that things worked as expected though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to this?

 +#, fuzzy
+msgid ""
+msgstr ""

If so, I'd suggest just removing the empty string from where you're extracting it (probably https://github.com/theforeman/foreman_remote_execution/pull/145/files#diff-4354b6d435b32105d6decf507c6bca49R7). It's unclear that you're actually exercising the code mentioned here if you're not doing a pull and merge.

As an aside, I'll try and review that PR as the strings are not good enough to translate.

@domcleal
Copy link
Contributor Author

Seems plugins are somewhat tricky with .edit.po, as after doing a tx pull you'd then need to re-run the rake task in core. I'll have a longer look at that soon, thanks for testing it.

@dLobatog
Copy link
Member

@domcleal ping?

@bkearney
Copy link
Contributor

@domcleal Can you take a look at https://github.com/bkearney/foreman/commits/bkearney-8874-i18n-failures. I was able to get the plugins to generate correctly. That patch is a rebase of yours onto develop, and then a small patch on top of it.

@domcleal
Copy link
Contributor Author

How does that work from the developer's perspective? They run rake task, run tx pull, run the rake task again manually?

@bkearney
Copy link
Contributor

@domcleal

assuming that the plugin is configured to tx pull to domain.edit.po, the process would need to be:

a) from the foreman directory, run rake plugin:gettext[$PLUGIN_NAME]
b) from the plugin directory run tx pull -f
c) then either run a msgmerge from the plugin directory, or do step (a) again.

To be honest, I dont know how often the user needs to do a,b, and c. It seems like (a) should be done on a weekly basis, and (b,c) should be done right before release.

If the plugin is not using edit files, then I dont think step c is needed.

@domcleal
Copy link
Contributor Author

Yes, that's the set of steps I was unhappy with in #2096 (comment). There's also an additional step after running the core rake task in (c) as the merged POs have to be recompiled into MO files (usually by running make in the plugin), which should be done with an extra target in the plugin's Makefile. I think we'll have to live with this four-step process for now.

theforeman/foreman_plugin_template#13 shows the matching changes from the plugin perspective, and I've outlined the steps in the plugin maintainer's docs here: http://projects.theforeman.org/projects/foreman/wiki/How_to_Create_a_Plugin#Pulling-translations-from-Transifex

3.1.13 adds an intermediate .edit.po file alongside each .po, which is meant
to be kept outside of SCM and updated by users, whereupon it's merged back into
the .po on the next rake gettext:find execution.

Previously we overwrote all gettext .po file changes with files directly from
Transifex, but now these are downloaded to .edit.po and gettext merges them
back in.  Fuzzy merges have been disabled as they were inaccurate.
@lzap
Copy link
Member

lzap commented Feb 3, 2016

Tested with Foreman Discovery (with theforeman/foreman_discovery#244).

end

Foreman::Gettext::Support.add_text_domain args[:engine], "#{@engine_root}/locale"
ENV['TEXTDOMAIN'] = args[:engine]
Foreman::Gettext::Support.add_text_domain @domain, "#{@engine_root}/locale"

Rake::Task['gettext:find'].invoke
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, I rarely see that this line fails with Nil exception, the task is sometimes not available:

# rake plugin:gettext[foreman_discovery]
...
rake aborted!
NoMethodError: undefined method `match' for nil:NilClass
/home/lzap/work/foreman/lib/tasks/gettext.rake:39:in `block in <top (required)>'
Tasks: TOP => gettext:po:update => gettext:po:ru:update
(See full trace by running task with --trace)

Ori reproduced this as well, but since this was there before this patch, I am merging this and we can attempt to find this later.

@lzap
Copy link
Member

lzap commented Feb 3, 2016

Merged as 4406f5a, thank you!

@lzap lzap closed this Feb 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants