Giter Site home page Giter Site logo

gettext's People

Contributors

284km avatar 375gnu avatar 3dd13 avatar bkerensa avatar cosmo0920 avatar evgeni avatar geekq avatar glacials avatar gogainda avatar grosser avatar hallelujah avatar ikaronen-relex avatar jordimassaguerpla avatar joshcooper avatar kitaitimakoto avatar kou avatar lslezak avatar lunar-debian avatar masone avatar michaelhoste avatar mutoh avatar myokoym avatar no6v avatar rgraff avatar tietew avatar ujh avatar vilius avatar yemartin avatar ynojima avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

gettext's Issues

rxgettext writes location paths relative to output file directory

This bug is originally reported as Debian bug 726946.

I noticed something really weird in rxgettext.
It seems that its output .pot file includes location paths relative to the destination directory, rather than to the current working directory!

I am not sure this causes problems with ruby-gettext library, but it sure looks unusual and awkward.

I'll show the issue with my usual test case, described in bug #684182 .

Let's start with the example application in a directory:

  $ tree
  .
  └── myapplication.rb

  0 directories, 1 file

Then, let's create a subdirectory:

  $ mkdir po

and create the .pot file with xgettext:

  $ xgettext --add-comments=TRANSLATORS --no-wrap \
             --copyright-holder="Francesco Poli" \
             --package-name=myapplication --package-version=0.1 \
             --msgid-bugs-address="[email protected]" \
             --language=python \
             myapplication.rb -o po/myapplication_XGETTEXT.pot
  $ cat po/myapplication_XGETTEXT.pot
  # SOME DESCRIPTIVE TITLE.
  # Copyright (C) YEAR Francesco Poli
  # This file is distributed under the same license as the PACKAGE package.
  # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
  #
  #, fuzzy
  msgid ""
  msgstr ""
  "Project-Id-Version: myapplication 0.1\n"
  "Report-Msgid-Bugs-To: [email protected]\n"
  "POT-Creation-Date: 2013-10-20 22:35+0200\n"
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  "Language-Team: LANGUAGE <[email protected]>\n"
  "Language: \n"
  "MIME-Version: 1.0\n"
  "Content-Type: text/plain; charset=CHARSET\n"
  "Content-Transfer-Encoding: 8bit\n"

  #: myapplication.rb:24
  msgid "Hello everybody!\n"
  msgstr ""

  #: myapplication.rb:27
  msgid "You are running an internationalized Ruby program.\n"
  msgstr ""

  #. TRANSLATORS: %d is the number of already printed messages
  #: myapplication.rb:31
  #, python-format
  msgid "You have already seen %d translatable messages.\n"
  msgstr ""

  #: myapplication.rb:33
  msgid "Is this message # 3 or # 4 ?\n"
  msgstr ""

  #: myapplication.rb:35
  msgid "OK, I am tired...\n"
  msgstr ""

  #: myapplication.rb:37
  msgid "Goodbye!\n"
  msgstr ""

This is OK.
Let's try with rxgettext:

  $ rxgettext --add-comments=TRANSLATORS --no-wrap \
              --copyright-holder="Francesco Poli" \
              --package-name=myapplication --package-version=0.1 \
              --msgid-bugs-address="[email protected]" \
              myapplication.rb -o po/myapplication_RXGETTEXT.pot
  $ cat po/myapplication_RXGETTEXT.pot
  # SOME DESCRIPTIVE TITLE.
  # Copyright (C) YEAR Francesco Poli
  # This file is distributed under the same license as the myapplication package.
  # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
  #
  #, fuzzy
  msgid ""
  msgstr ""
  "Project-Id-Version: myapplication 0.1\n"
  "Report-Msgid-Bugs-To: [email protected]\n"
  "POT-Creation-Date: 2013-10-20 22:39+0200\n"
  "PO-Revision-Date: 2013-10-20 22:39+0200\n"
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  "Language-Team: LANGUAGE <[email protected]>\n"
  "Language: \n"
  "MIME-Version: 1.0\n"
  "Content-Type: text/plain; charset=UTF-8\n"
  "Content-Transfer-Encoding: 8bit\n"
  "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

  #: ../myapplication.rb:24
  msgid "Hello everybody!\n"
  msgstr ""

  #: ../myapplication.rb:27
  msgid "You are running an internationalized Ruby program.\n"
  msgstr ""

  #. TRANSLATORS: %d is the number of already printed messages
  #: ../myapplication.rb:31
  msgid "You have already seen %d translatable messages.\n"
  msgstr ""

  #: ../myapplication.rb:33
  msgid "Is this message # 3 or # 4 ?\n"
  msgstr ""

  #: ../myapplication.rb:35
  msgid "OK, I am tired...\n"
  msgstr ""

  #: ../myapplication.rb:37
  msgid "Goodbye!\n"
  msgstr ""

Please note that the location paths are "../myapplication.rb", rather than "myapplication.rb".
I think that rxgettext should behave like xgettext in this respect.

Please fix this bug and/or forward this bug report upstream.
Thanks for your time!

test/tools/test_xgettext.rb has unneeded iconv require

test/tools/test_xgettext.rb has iconv require on the line 21, and it seems this is unneeded.
WIth ruby 2.0.0 iconv is removed from ruby-core, so now test fails like:

+ ruby -Ilib:test test/run-test.rb
/usr/share/gems/gems/test-unit-notify-0.3.0/lib/test/unit/notify.rb:106: warning: assigned but unused variable - expire_time
/builddir/build/BUILD/rubygem-gettext-2.3.7/usr/share/gems/gems/gettext-2.3.7/test/test_locale_path.rb:74: warning: assigned but unused variable - default_path_rules
/builddir/build/BUILD/rubygem-gettext-2.3.7/usr/share/gems/gems/gettext-2.3.7/lib/gettext/tools/po.rb:194: warning: assigned but unused variable - msgctxt
/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- iconv (LoadError)
    from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:45:in `require'
    from /builddir/build/BUILD/rubygem-gettext-2.3.7/usr/share/gems/gems/gettext-2.3.7/test/tools/test_xgettext.rb:21:in `<top (required)>'
    from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:45:in `require'
    from /usr/share/rubygems/rubygems/core_ext/kernel_require.rb:45:in `require'
    from test/run-test.rb:44:in `block (2 levels) in <main>'
    from test/run-test.rb:43:in `each'
    from test/run-test.rb:43:in `block in <main>'
    from test/run-test.rb:42:in `chdir'
    from test/run-test.rb:42:in `<main>

(log: http://kojipkgs.fedoraproject.org//work/tasks/3537/5063537/build.log
toplevel URL: http://koji.fedoraproject.org/koji/taskinfo?taskID=5063537 )

Just commenting out requiring iconv on the line 21 seems to work.

false positive on string to translate?

When generating a pot file with ruby-gettext for the puppet project, we found some strings were identified for externalization which surprised us.

The code in question is a series of method definitions, here: https://github.com/puppetlabs/puppet/blob/master/lib/puppet/pops/types/type_formatter.rb#L115-L137.

An example is:

  # @api private
  def string_PAnyType(_)     ; @bld << 'Any'     ; end

For some reason, when parsed by ruby-gettext, this method and others like it result in entries in our pot file:

#. @api private
msgid "Any"
msgstr ""

This full generated pot file is in puppetlabs/puppet#5366.

Naively, it appears this combination of parenthesis and underscores in our method names is tripping up the parser? Or are we doing something incorrect here?

Our invocation is:

rxgettext -o locales/puppet.pot --no-wrap \
--sort-by-file \
--no-location \
--add-comments \
--msgid-bugs-address 'https://tickets.puppetlabs.com' \
--package-name 'Puppet automation framework' \
--package-version '4.8.1-116-g6dfd145 \
' --copyright-holder='Puppet, Inc.' \
--copyright-year=2016 <list of files...>

How is the header output customized?

Hello there, gettext maintainers! 👋🏼

I'm new to the gettext world, and to using this gem. Running rake gettext:find produces a boilerplate header that looks like this:

# English translations for foo package.
# Copyright (C) 2021 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the foo package.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2021.
#
msgid ""
msgstr ""
"Project-Id-Version: github 1.0.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2021-01-22 21:21-0800\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: English\n"
"Language: en\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"\n"

How can I configure my Ruby project so that values like FIRST AUTHOR and EMAIL@ADDRESS are filled with real values when I run the rake task? I didn't see any documentation about how this works, but would be happy to contribute a pull request with docs for that, once I figure this out.

Thanks!

cc @mjacobus @bigzoo

Purpose of the edit.po file

Thanks to Kouhei's help, I now understand perfectly the purpose of the edit.po files:

It's for reducing needless changes from repository. The needless changes are location changes such as: "#: .../a.rb:29" -> "#: .../a.rb:30".
These changes are needless for version control but these changes are very useful on translation.
So I introduced edit.po. edit.po (not version controlled) include them but po (version controlled) doesn't include them. By the split, we can exist together "easy to translation by location information" and "reducing needless changes from repository".

So I'm using this gem in an a opensource project with a lot of legacy code, of course in addition to the gettext_i18n_rails and fast_gettext. Usually when we change something in the code we create a pot file and submit that to the translation team. Except this time, only the line numbers changed not the translated text itself, so I noticed that both the generated po and edit.po files contain the original text, the translated text and the right line numbers!

My question is: how is this possible? Not only the gem figured out the correct line numbers, but also it matched the original text with the old translation! Does the gettext:find uses the old po files for generating the new one?

Thanks!

Ignored Gettext syntax when <%- is used in ERB files

It seems that there is a parsing issue when <%- is used in an ERB file.

In this example, "Hello" is not added to the PO(T) file:

<%- content_for :title, "Title" %>

<%= _("Hello") %>

I don't exactly know why, but using:

<%= content_for :title, "Title" %>

<%= _("Hello") %>

or something like:

<%- "Title" %>

<%= _("Hello") %>

solves this issue.

Do you have any idea why this happens?

No fuzzy messages

Is there any way to completely disable all fuzzy message merges? It appears that rmsgmerge does not support the --no-fuzzy-matching (-N) option from the regular gettext binary, so I've not been able to prevent the confusing fuzzy translations from entering my .po files.

If not, is there any intention on supporting this?

please implement command-line options for rgettext to fill in some fields

This report is copied from Debian bugzilla.

I noticed that rgettext lacks useful command-line options to specify actual values to be used in stead of placeholders.

Please see the test case described in bug #684182.

I think it would be great if rgettext had appropriate command-line options to specify:

(A) what should be put in the output .pot file in stead of "Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER"

(B) what should be put in stead of "PACKAGE"

(C) what should be put in stead of "VERSION"

(D) which e-mail address should be put in the Report-Msgid-Bugs-To field (a field that rgettext does not even generate, currently)

Please implement these additional features and/or forward this bug report upstream.

3.1.8 test fails on test_fuzzy_matching_entry

ruby gettext 3.1.8 and git head test suite fails on test_fuzzy_matching_entry like:

Failure: test_fuzzy_matching_entry(TestToolsMsgMerge::TestMerger::TestAddFuzzy)
/home/tasaka1/rpmbuild/fedora-specific/TMP/rubygem-gettext/master/rubygem-gettext/Upst/gettext/test/tools/test_msgmerge.rb:284:in `test_fuzzy_matching_entry'
     281: 
     282:         assert_false(merged_po.has_key?("helol"))
     283:         assert_true(merged_po.has_key?("hello"))
  => 284:         assert_equal("bonjour", merged_po["hello"].msgstr)
     285:         assert_equal("fuzzy", merged_po["hello"].flag)
     286:       end
     287: 
<"bonjour"> expected but was
<"">

Now using Fedora 23 x86_64, with

$ ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]

"'ErbParser' is ignored." at Arch Linux

I am running gitlab at Arch Linux with ruby 2.6 installed and see following warning:

'ErbParser' is ignored.
'RubyParser' is ignored.

Debugging it a little bit more I found that it came from bundled gettext. I added more debug entries to the source code and found that it cannot find class RubyToken:

uninitialized constant GetText::RubyLexX::RubyToken
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/parser/ruby.rb:120:in `<class:RubyLexX>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/parser/ruby.rb:22:in `<module:GetText>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/parser/ruby.rb:21:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/parser/erb.rb:13:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:62:in `block in <class:XGetText>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:60:in `each'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:60:in `<class:XGetText>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:31:in `<module:Tools>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:30:in `<module:GetText>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:29:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext_i18n_rails_js-1.3.0/lib/gettext_i18n_rails_js/parser/base.rb:26:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext_i18n_rails_js-1.3.0/lib/gettext_i18n_rails_js/parser.rb:26:in `require_relative'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext_i18n_rails_js-1.3.0/lib/gettext_i18n_rails_js/parser.rb:26:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext_i18n_rails_js-1.3.0/lib/gettext_i18n_rails_js.rb:37:in `require_relative'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext_i18n_rails_js-1.3.0/lib/gettext_i18n_rails_js.rb:37:in `<top (required)>'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:74:in `require'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:74:in `block (2 levels) in require'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:69:in `each'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:69:in `block in require'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:58:in `each'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:58:in `require'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler.rb:174:in `require'
/usr/share/webapps/gitlab/config/application.rb:11:in `<top (required)>'
/usr/share/webapps/gitlab/Rakefile:5:in `require'
/usr/share/webapps/gitlab/Rakefile:5:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/rake_module.rb:29:in `load'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/rake_module.rb:29:in `load_rakefile'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:703:in `raw_load_rakefile'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:104:in `block in load_rakefile'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:103:in `load_rakefile'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:82:in `block in run'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:80:in `run'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/bin/rake:23:in `load'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/bin/rake:23:in `<top (required)>'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli/exec.rb:63:in `load'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli/exec.rb:28:in `run'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli.rb:476:in `exec'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli.rb:30:in `dispatch'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli.rb:24:in `start'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/exe/bundle:46:in `block in <top (required)>'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/exe/bundle:34:in `<top (required)>'
/usr/bin/bundle:23:in `load'
/usr/bin/bundle:23:in `<main>'
'ErbParser' is ignored.
uninitialized constant GetText::RubyLexX::RubyToken
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/parser/ruby.rb:120:in `<class:RubyLexX>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/parser/ruby.rb:22:in `<module:GetText>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/parser/ruby.rb:21:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:62:in `block in <class:XGetText>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:60:in `each'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:60:in `<class:XGetText>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:31:in `<module:Tools>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:30:in `<module:GetText>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext-3.2.9/lib/gettext/tools/xgettext.rb:29:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext_i18n_rails_js-1.3.0/lib/gettext_i18n_rails_js/parser/base.rb:26:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext_i18n_rails_js-1.3.0/lib/gettext_i18n_rails_js/parser.rb:26:in `require_relative'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext_i18n_rails_js-1.3.0/lib/gettext_i18n_rails_js/parser.rb:26:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext_i18n_rails_js-1.3.0/lib/gettext_i18n_rails_js.rb:37:in `require_relative'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/gettext_i18n_rails_js-1.3.0/lib/gettext_i18n_rails_js.rb:37:in `<top (required)>'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:74:in `require'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:74:in `block (2 levels) in require'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:69:in `each'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:69:in `block in require'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:58:in `each'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/runtime.rb:58:in `require'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler.rb:174:in `require'
/usr/share/webapps/gitlab/config/application.rb:11:in `<top (required)>'
/usr/share/webapps/gitlab/Rakefile:5:in `require'
/usr/share/webapps/gitlab/Rakefile:5:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/rake_module.rb:29:in `load'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/rake_module.rb:29:in `load_rakefile'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:703:in `raw_load_rakefile'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:104:in `block in load_rakefile'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:103:in `load_rakefile'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:82:in `block in run'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:186:in `standard_exception_handling'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/lib/rake/application.rb:80:in `run'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/gems/rake-12.3.3/exe/rake:27:in `<top (required)>'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/bin/rake:23:in `load'
/usr/share/webapps/gitlab/vendor/bundle/ruby/2.6.0/bin/rake:23:in `<top (required)>'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli/exec.rb:63:in `load'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli/exec.rb:28:in `run'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli.rb:476:in `exec'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli.rb:30:in `dispatch'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/cli.rb:24:in `start'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/exe/bundle:46:in `block in <top (required)>'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/lib/ruby/gems/2.6.0/gems/bundler-2.1.2/exe/bundle:34:in `<top (required)>'
/usr/bin/bundle:23:in `load'
/usr/bin/bundle:23:in `<main>'
'RubyParser' is ignored.

Could you please help me to understand where class RubyToken suppose to come from?

gettext can't handle HAML files properly

We're running into a lot of headaches trying to parse HAML files, most of them can be traced back to the rake gettext:find task using ruby_parser somewhere, and using Ruby 1.9.

If gettext could be rewritten to use ripper instead of ruby_parser when running on Ruby 1.9, this might fix things?

See here:

http://rails-bestpractices.com/blog/posts/22-use-ripper-instead-of-ruby_parser

Problems are all over the place, and even when we remove all Ruby 1.9 syntax from a file, gettext and ruby_parser still fail. For example this file, it makes rake gettext:find crash:

https://github.com/zhdk/madek/blob/master/app/assets/javascripts/tmpl/media_resource/thumb_box/actions/menu.tmpl.haml

With the following error:

Can't change the value of true

And this error comes from ruby_parser, but could be prevented if gettext used a different parser.

I've reported a similar ticket at ruby_parser anyhow, to see if the problem might be there:

seattlerb/ruby_parser#43

use fuzzy vs warn about fuzzy

I currently have this pull open on fast_gettext, but I feel gettext would be the better place for it, so that everyone using something gettexty can benefit.

It distinguishes between using fuzzy and warning about fuzzy, so I can get warnings but do not have to use fuzzy.
Are you ok with adding this to gettext ?

gettext:find not finding all message IDs if .erb file contains -%> closing tags

Message IDs are not picked up by gettext:find / rxgettext if .erb file contains -%> closing tag.

Neither ID is picked up:

<% content_for :javascript_includes do %>
<%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" %>
<% end -%>
<%= fa_icon('building', title: _("View account's calendar")) %> <%= _("Account's events") %>

Result:

% rxgettext gettext_test.erb
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-03-17 17:38+0200\n"
"PO-Revision-Date: 2020-03-17 17:38+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

If the ending tag is changed from '-%>' to '%>' it works:

<% content_for :javascript_includes do %>
<%= javascript_include_tag "https://www.gstatic.com/charts/loader.js" %>
<% end %>
<%= fa_icon('building', title: _("View account's calendar")) %> <%= _("Account's events") %>
% rxgettext gettext_test.erb
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-03-17 17:37+0200\n"
"PO-Revision-Date: 2020-03-17 17:37+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

#: gettext_test.erb:4
msgid "View account's calendar"
msgstr ""

#: gettext_test.erb:4
msgid "Account's events"
msgstr ""

-%> is a valid end tag, and thus it should be allowed.
https://api.rubyonrails.org/classes/ActionView/Base.html

Breaking change with 3.3.0

Going from zero ruby requirements to requiring 2.5.0 is a breaking change. We now have a bunch of things breaking due to this latest requirement to ruby >= 2.5.0.

Is there a reason to not just create this as 4.0 and force that requirement on the next major version instead? Is this a actual requirement due to library usage, is 2.4.x not compatible.

gettext does not parse TStrings after bitwise or "|"

Since commit 41ee55b all occurences of TStrings are ignored after a bitwise or "|". I think it is caused by the exclusion of block parameters with the process_on_op method and the early return in process_on_ident. Both, block parameter limiters and the bitwise or operator, are recoognized as :on_op by the Ripper Lexer.

Here is a dummy example to demonstrate the problem:

test_file.rb:

[1, 2].map do |e|
  puts _('tstring1')
  result = e | 2
  puts _('tstring2')
  result
end
GetText::RubyParser.new('test_file.rb').parse
> [#<GetText::POEntry:0x000055ba94c53218 
          @type=:normal,
          @param_type=[:msgid, :separator, :msgstr], 
          @translator_comment=nil,
          @extracted_comment=nil,
          @references=["test_file.rb:2"],
          @flags=[],
          @previous=nil,
          @msgctxt=nil,
          @msgid="tstring1",
          @msgid_plural=nil,
          @msgstr=nil>]

Even though I would expect an output like this:

> [#<GetText::POEntry:0x000055ba94c53218 
          @type=:normal,
          @param_type=[:msgid, :separator, :msgstr], 
          @translator_comment=nil,
          @extracted_comment=nil,
          @references=["test_file.rb:2"],
          @flags=[],
          @previous=nil,
          @msgctxt=nil,
          @msgid="tstring1",
          @msgid_plural=nil,
          @msgstr=nil>,
   #<GetText::POEntry:0x000055ba94c04820  
          @type=:normal,
          @param_type=[:msgid, :separator, :msgstr],
          @translator_comment=nil, 
          @extracted_comment=nil,
          @references=["test_file.rb:4"],
          @flags=[], 
          @previous=nil, 
          @msgctxt=nil,
          @msgid="tstring2",
          @msgid_plural=nil,
          @msgstr=nil>]

Dasherized Locales per RFC4646

I'm working on a translation pipeline for an application, and I've had to write some tooling to convert between the Underscored vs. Dashed locales (e.g. en_US vs. en-US) in order to support some downstream tooling.

I did a bit of digging, and it looks like RFC4646 specifies the use of dashes, and does not included _.

I don't mind putting together a PR to add support for dasherized locale names, however wanted to double check that this would be accepted before doing the work.

Thanks!

rxgettext: please implement a command-line option to set the copyright YEAR

This issue is originally reported as Debain bug 726941.

it would be great if rxgettext had a command-line option to specify what should be put in the output .pot file in stead of the "YEAR" in the copyright notice.

In other words, let's consider (again) the test case described in bug #684182.

If I create the .pot with rxgettext:

  $ rxgettext --add-comments=TRANSLATORS --no-wrap \
              --copyright-holder="Francesco Poli" \
              --package-name=myapplication --package-version=0.1 \
              --msgid-bugs-address="[email protected]" \
              myapplication.rb -o myapplication_RXGETTEXT.pot

the copyright notice in the output .pot is:

  $ grep Copyright myapplication_RXGETTEXT.pot 
  # Copyright (C) YEAR Francesco Poli

As far as I know, there's no way to tell rxgettext to replace that "YEAR" with, say, "2012", "1999-2013", or "1998, 2005-2007, 2012".

I think it would be useful to have some command-line option to do that. Something like

  $ rxgettext ... --copyright-year="1999-2013" ...

Please implement this additional feature and/or forward this bug report upstream.
Thanks for your time!

gettext 3.1.5 seems to require >=text 1.3.0

With text 1.2.3 installed I am seeing test failures similar to

Error: test_obsolete_entry(TestToolsMsgMerge::TestMerger)
  ArgumentError: wrong number of arguments (3 for 2)
/usr/lib64/ruby/gems/1.9.1/gems/text-1.2.3/lib/text/levenshtein.rb:32:in `distance'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/lib/gettext/tools/msgmerge.rb:254:in `compute_distance'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/lib/gettext/tools/msgmerge.rb:227:in `block in find'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/lib/gettext/tools/msgmerge.rb:226:in `each'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/lib/gettext/tools/msgmerge.rb:226:in `find'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/lib/gettext/tools/msgmerge.rb:124:in `merge_definition'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/lib/gettext/tools/msgmerge.rb:98:in `block in merge'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/lib/gettext/po.rb:174:in `each_value'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/lib/gettext/po.rb:174:in `each'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/lib/gettext/tools/msgmerge.rb:96:in `merge'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/test/tools/test_msgmerge.rb:39:in `merge'
/var/tmp/portage/dev-ruby/ruby-gettext-3.1.5/work/ruby19/ruby-gettext-3.1.5/test/tools/test_msgmerge.rb:305:in `test_obsolete_entry'
     302:     def test_obsolete_entry
     303:       @po["hello"] = "bonjour"
     304:       @pot["hi"] = "salut"
  => 305:       merged_po = merge
     306: 
     307:       assert_equal("salut", merged_po["hi"].msgstr)
     308:       assert_false(merged_po.has_key?("hello"))

Upgrading to text 1.3.0 causes all tests to pass.

msgcat method / tool

Are you going to support functionality similar to GNU msgcat command? I would like to concatenate and merge multiple .po files to one and preserving their translations.

msgmerge is only meant for applying a new template to existing translation. It will discard any localizations in the second file by design, isn't it?

Question about usage of .edit.po and rate task ordering

Hey,

I'm trying to work out how to make best use of the .edit.po files that started being generated in 3.1.13, and would appreciate some guidance or an example project that's making use of them.

I'd first like to clarify exactly what they're for: is the idea that gettext generates the .edit.po for external editing and syncing of translations, and then merges that into the .po which is the file actually used? Would you keep .edit.po outside of version control?

Our project uses gettext_i18n_rails which defines gettext:find and setup via GetText::Tools::Task.define. We import updates to .po files from the Transifex web site with "tx pull -f", which can be configured to update locale/<lang>/foreman.po etc.

Now, I could run gettext:find (aka gettext:po:update) to generate .po and .edit.po files, then tx pull to sync translations to the .edit.po files, then run gettext:find again to re-sync .edit.po to .po. This appears to work, though it is incredibly slow.

Or should I perhaps download .po files from Transifex to .edit.po, then run gettext:find which merges them into .po?

Thanks for any thoughts on the subject.

gettext:find does not find interpolated strings in .rb files

It was indicated here: grosser/gettext_i18n_rails#146 that i should raise this issue with the gettext gem:

Running gettext:find doesn't seem to find interpolated strings in .rb files.

#In a .rb file
test = _("Test: this key is found by gettext")
test2 = "#{_("Test: this key is not found by gettext")}"

In .haml files however, the above examples both work fine and gettext:find correctly identifies both as being strings to be translated.

messages from installed rmsgfmt or so cannot be localized

With (ruby-)gettext 2.2.1, rmsgfmt --help clearly shows localized messages:

$  ./bin/rmsgfmt --help
Usage: ./bin/rmsgfmt input.po [-o output.mo]

poファイルからバイナリのメッセージカタログファイル(moファイル)を生成します。

オプション:
    -o, --output=FILE                出力ファイルを指定します
        --version                    バージョンを表示します

(in LANG=ja_JP.utf8). But with 2.3.2, rmgsfmt --help does not show localized messages:

$ ./bin/rmsgfmt --help
Usage: ./bin/rmsgfmt input.po [-o output.mo]

Generate binary message catalog from textual translation description.

Specific options:
    -o, --output=FILE                write output to specified file
        --version                    display version information and exit

It seems that with, gettext-2.3.2.gem, (for example) lib/gettext/tools/msgfmt.rb contains 'bindtextdomain("rgettext")' and there is po/ja/rgettext.po, however these po files are
not compiled into .mo gettext catalogues and not installed.

Missing pluralization forms

We noticed that some pluralization forms are missing from here: https://github.com/ruby-gettext/gettext/blob/master/lib/gettext/tools/msginit.rb#L322

One of the important missing ones is Arabic.

I have 2 questions:

1. Rules importation

Would you accept a pull request that extend these rules using the CLDR official source extracted to valid GetText rules using this tool?

export-plural-rules prettyjson > file.json returns a file like this, and the idea would be to add it to this project and load the pluralization rules from it in the plural_forms method:

{
    "af": {
        "name": "Afrikaans",
        "formula": "n != 1",
        "plurals": 2,
        "cases": [
            "one",
            "other"
        ],
        "examples": {
            "one": "1",
            "other": "0, 2~16, 100, 1000, 10000, 100000, 1000000, …"
        }
    },
    "ak": {
        "name": "Akan",
        "formula": "n > 1",
        "plurals": 2,
        "cases": [
            "one",
            "other"
        ],
        "examples": {
            "one": "0, 1",
            "other": "2~17, 100, 1000, 10000, 100000, 1000000, …"
        }
    },
 ...
}

We could even simplify it to have a file like this:

{
    "af": {
        "formula": "n != 1",
        "plurals": 2
    },
    "ak": {
        "formula": "n > 1",
        "plurals": 2
    },
 ...
}

or even transform it into a Ruby hash. What would be your preference?

2. nplurals > 4

There are currently no more than 4 pluralization forms, and it will change with Arabic that needs 6 of them.

Do you expect that there will be problems with the rest of the code? Or just improving the plural_forms method will be enough to make it work with msgstr[4] and msgstr[5]?


Thank you for any feedback that you may have on this.

I am volunteering to work on this issue with your guidance.

3.3.9 does not pass tests without red-datasets

With gettext 3.3.9 without red-datasets:

.................................F
=============================================================================================================================================================================================================
Failure: test_cs(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:384:in `test_cs'
     381:     end
     382: 
     383:     def test_cs
  => 384:       assert_equal("nplurals=3; " +
     385:                    "plural=(n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2;",
     386:                    @msginit.__send__(:plural_forms, "cs"))
     387:     end
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=3; plural=(n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=3; plural=(n == 1) ? 0 : (n >= 2 && n <= 4) ? 1 : 2;
=============================================================================================================================================================================================================
F
=============================================================================================================================================================================================================
Failure: test_en(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:335:in `test_en'
     332:     end
     333: 
     334:     def test_en
  => 335:       assert_equal("nplurals=2; plural=n != 1;",
     336:                    @msginit.__send__(:plural_forms, "en"))
     337:     end
     338: 
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=2; plural=n != 1;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=2; plural=n != 1;
=============================================================================================================================================================================================================
F
=============================================================================================================================================================================================================
Failure: test_fr(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:340:in `test_fr'
     337:     end
     338: 
     339:     def test_fr
  => 340:       assert_equal("nplurals=2; plural=n > 1;",
     341:                    @msginit.__send__(:plural_forms, "fr"))
     342:     end
     343: 
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=2; plural=n > 1;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=2; plural=n > 1;
=============================================================================================================================================================================================================
F
=============================================================================================================================================================================================================
Failure: test_ga(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:353:in `test_ga'
     350:     end
     351: 
     352:     def test_ga
  => 353:       assert_equal("nplurals=5; " +
     354:                    "plural=(n == 1) ? 0 : (n == 2) ? 1 : " +
     355:                    "(n >= 3 && n <= 6) ? 2 : (n >= 7 && n <= 10) ? 3 : 4;",
     356:                    @msginit.__send__(:plural_forms, "ga"))
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=5; plural=(n == 1) ? 0 : (n == 2) ? 1 : (n >= 3 && n <= 6) ? 2 : (n >= 7 && n <= 10) ? 3 : 4;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=5; plural=(n == 1) ? 0 : (n == 2) ? 1 : (n >= 3 && n <= 6) ? 2 : (n >= 7 && n <= 10) ? 3 : 4;
=============================================================================================================================================================================================================
F
=============================================================================================================================================================================================================
Failure: test_ja(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:330:in `test_ja'
     327:     end
     328: 
     329:     def test_ja
  => 330:       assert_equal("nplurals=1; plural=0;",
     331:                    @msginit.__send__(:plural_forms, "ja"))
     332:     end
     333: 
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=1; plural=0;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=1; plural=0;
=============================================================================================================================================================================================================
F
=============================================================================================================================================================================================================
Failure: test_lt(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:367:in `test_lt'
     364:     end
     365: 
     366:     def test_lt
  => 367:       assert_equal("nplurals=3; " +
     368:                    "plural=((n % 10) == 1) && " +
     369:                    "((n % 100) < 11 || (n % 100) > 19) ? 0 : " +
     370:                    "((n % 10) >= 2 && (n % 10) <= 9) && " +
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=3; plural=((n % 10) == 1) && ((n % 100) < 11 || (n % 100) > 19) ? 0 : ((n % 10) >= 2 && (n % 10) <= 9) && ((n % 100) < 11 || (n % 100) > 19) ? 1 : 2;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=3; plural=((n % 10) == 1) && ((n % 100) < 11 || (n % 100) > 19) ? 0 : ((n % 10) >= 2 && (n % 10) <= 9) && ((n % 100) < 11 || (n % 100) > 19) ? 1 : 2;
=============================================================================================================================================================================================================
F
=============================================================================================================================================================================================================
Failure: test_lv(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:345:in `test_lv'
     342:     end
     343: 
     344:     def test_lv
  => 345:       assert_equal("nplurals=3; " +
     346:                    "plural=((n % 10) == 1) && ((n % 100) != 11) ? 0 : " +
     347:                    "((n % 10) == 0) || ((n % 100) >= 11 && (n % 100) <= 19) " +
     348:                    "? 1 : 2;",
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=3; plural=((n % 10) == 1) && ((n % 100) != 11) ? 0 : ((n % 10) == 0) || ((n % 100) >= 11 && (n % 100) <= 19) ? 1 : 2;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=3; plural=((n % 10) == 1) && ((n % 100) != 11) ? 0 : ((n % 10) == 0) || ((n % 100) >= 11 && (n % 100) <= 19) ? 1 : 2;
=============================================================================================================================================================================================================
F
=============================================================================================================================================================================================================
Failure: test_pl(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:390:in `test_pl'
     387:     end
     388: 
     389:     def test_pl
  => 390:       assert_equal("nplurals=3; " +
     391:                    "plural=(n == 1) ? 0 : " +
     392:                    "((n % 10) >= 2 && (n % 10) <= 4) && " +
     393:                    "((n % 100) < 12 || (n % 100) > 14) ? 1 : 2;",
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=3; plural=(n == 1) ? 0 : ((n % 10) >= 2 && (n % 10) <= 4) && ((n % 100) < 12 || (n % 100) > 14) ? 1 : 2;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=3; plural=(n == 1) ? 0 : ((n % 10) >= 2 && (n % 10) <= 4) && ((n % 100) < 12 || (n % 100) > 14) ? 1 : 2;
=============================================================================================================================================================================================================
F
=============================================================================================================================================================================================================
Failure: test_ro(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:360:in `test_ro'
     357:     end
     358: 
     359:     def test_ro
  => 360:       assert_equal("nplurals=3; " +
     361:                    "plural=(n == 1) ? 0 : " +
     362:                    "(n == 0) || ((n % 100) >= 2 && (n % 100) <= 19) ? 1 : 2;",
     363:                    @msginit.__send__(:plural_forms, "ro"))
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=3; plural=(n == 1) ? 0 : (n == 0) || ((n % 100) >= 2 && (n % 100) <= 19) ? 1 : 2;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=3; plural=(n == 1) ? 0 : (n == 0) || ((n % 100) >= 2 && (n % 100) <= 19) ? 1 : 2;
=============================================================================================================================================================================================================
F
=============================================================================================================================================================================================================
Failure: test_ru(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:376:in `test_ru'
     373:     end
     374: 
     375:     def test_ru
  => 376:       assert_equal("nplurals=3; " +
     377:                    "plural=((n % 10) == 1) && ((n % 100) != 11) ? 0 : " +
     378:                    "((n % 10) >= 2 && (n % 10) <= 4) && " +
     379:                    "((n % 100) < 12 || (n % 100) > 14) ? 1 : 2;",
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=3; plural=((n % 10) == 1) && ((n % 100) != 11) ? 0 : ((n % 10) >= 2 && (n % 10) <= 4) && ((n % 100) < 12 || (n % 100) > 14) ? 1 : 2;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=3; plural=((n % 10) == 1) && ((n % 100) != 11) ? 0 : ((n % 10) >= 2 && (n % 10) <= 4) && ((n % 100) < 12 || (n % 100) > 14) ? 1 : 2;
=============================================================================================================================================================================================================
F
=============================================================================================================================================================================================================
Failure: test_sl(TestToolsMsgInit::TestPluralForms)
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:398:in `test_sl'
     395:     end
     396: 
     397:     def test_sl
  => 398:       assert_equal("nplurals=4; " +
     399:                    "plural=((n % 100) == 1) ? 0 : " +
     400:                    "((n % 100) == 2) ? 1 : " +
     401:                    "((n % 100) >= 3 && (n % 100) <= 4) ? 2 : 3;",
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:40:in `block (2 levels) in run'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `chdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:39:in `block in run'
/usr/share/ruby/tmpdir.rb:96:in `mktmpdir'
/home/tasaka1/rpmbuild/fedora-specific/RUBYGEMS/rubygem-gettext/rawhide/rubygem-gettext-3.3.9/usr/share/gems/gems/gettext-3.3.9/test/tools/test_msginit.rb:38:in `run'
<"nplurals=4; plural=((n % 100) == 1) ? 0 : ((n % 100) == 2) ? 1 : ((n % 100) >= 3 && (n % 100) <= 4) ? 2 : 3;"> expected but was
<"nplurals=; plural=;">

diff:
? nplurals=4; plural=((n % 100) == 1) ? 0 : ((n % 100) == 2) ? 1 : ((n % 100) >= 3 && (n % 100) <= 4) ? 2 : 3;
=============================================================================================================================================================================================================
.....................................................................................................
Finished in 4.795605263 seconds.
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
378 tests, 744 assertions, 11 failures, 0 errors, 0 pendings, 1 omissions, 0 notifications
97.0822% passed

Looks like

does nothing when red-datasets is not installed. Is this intentional? At least it is pleased that test suite passes even without red-datasets.

Error when parsing %W(text)

This seems related to #71

When parsing a file that looks like this:

class Example
  def test
    %W(text)
  end
end

The parser breaks with this error:

NoMethodError: undefined method `<<' for nil:NilClass
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/parser/ruby.rb:157:in `process_on_tstring_content'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/parser/ruby.rb:278:in `block in on_default'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/parser/ruby.rb:293:in `trace'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/parser/ruby.rb:275:in `on_default'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/2.5.0/ripper/filter.rb:66:in `block in parse'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/2.5.0/ripper/filter.rb:61:in `each'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/2.5.0/ripper/filter.rb:61:in `parse'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/parser/ruby.rb:430:in `parse_source'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/parser/ruby.rb:412:in `parse'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/parser/ruby.rb:329:in `parse'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/xgettext.rb:365:in `block in parse_path'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/xgettext.rb:360:in `each'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/xgettext.rb:360:in `parse_path'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/xgettext.rb:168:in `block in parse'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/xgettext.rb:166:in `each'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/xgettext.rb:166:in `parse'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/xgettext.rb:217:in `generate_pot'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/xgettext.rb:151:in `run'
/usr/local/var/rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/gettext-3.3.3/lib/gettext/tools/xgettext.rb:34:in `run'

Using %w instead of %W fixes the issue.

(Tested on GetText 3.3.2 and 3.3.3 with ruby 2.5 and 2.7)

msgmerge is very verbose

Hi,
msgcat supports --no-report-warning, but msgmerge does not. And msgmerge is very verbose about fuzzy message. Could it also have support for it?
Cheers!

Gettext parsing eval strings and that may cause slowness and security issue

In my ruby project, if I have a string like:

"#{puts("hello")}}"

Then when I'll parse it with Gettext, I got hello in my console. It's because the string is executed in this line: https://github.com/ruby-gettext/gettext/blob/master/lib/gettext/tools/parser/ruby.rb#L38

That's not so bad but if I have a string like this

"remove a file from disk #{FileUtils.rm('file.txt')}"

or

"remove users from DB #{User.destroy_all}"

it's already way more damaging.

Another issue with this is that it's slow down the parsing. It could be a slow request in the database (it's how I noticed that issue in the first place) or it could be a loop:

"slow request #{User.complex_scope.pluck(:id)}"
"slow loop #{100000000.times { |i| rand(i) }}"

I'm not sure why eval is called on this line. Is is really needed? What is the purpose? I would feel way more confortable if Gettext didn't try to execute my code when parsing the files.

EDIT : please take note that it's not even gettext string like _("") but only simple strings on the code. So I'm not sure why Gettext is trying to execute them.

cannot add my custom parsers

add_parser used to be global, so I could just add a parser and then just use update_pofile,
but now I have to instanciate my own XGettext and do all the dirty/undry work,
can you add back something like a class-level add_parser that then is used when making a new instance ?

Nn_() not recognised

Hi gettext team,

we are observing the parser in 3.3.7 not picking up Nn_() expression and dropping them from our .pot files. Any help would be appreciated.

Example: Nn_('T-Shirt', 'T-Shirts')

Our current version is 3.2.9

What happen to GetText.update_pofiles ?

Hi,

I'm trying to upgrade our GetText gem from 2.2.1 to latest, and the error message I'm having is undefined methodupdate_pofiles' for GetText:Module`.

# current usage on our webapp
GetText.update_pofiles "name", paths.sort, "name 2.0.0",
      :po_root => locale_path,
      :msgmerge => '--sort-by-file --no-wrap',
      :lang     => args[:lang] || ENV['lang']

Seems that the changelog stopped to be updated since that version, I would like to know what is the equivalent to that please.

Thank you

"n_" raises SystemStackError when modules are prepended

Code:

require 'gettext'

module Bar
end

class Foo
  include GetText
  bindtextdomain('foo')
  def foo
    n_('foo', 'foos', 1)
  end
end

class Foo
  prepend Bar
end

Foo.new.foo

Output:

% ruby -v test.rb
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
/.../gems/gettext-3.0.3/lib/gettext/class_info.rb:43: stack level too deep (SystemStackError)

Patch:

--- a/lib/gettext/class_info.rb
+++ b/lib/gettext/class_info.rb
@@ -38,7 +38,8 @@ module GetText
       end
       analyzed_classes << klass unless analyzed_classes.include? klass

-      klass.ancestors[1..-1].each do |a|
+      i = klass.ancestors.index(klass)
+      klass.ancestors[i+1..-1].each do |a|
         ret += related_classes_internal(a, all_classes, analyzed_classes)
         ret.uniq!
       end

gettext does not work with glade

Hello there! Before i start complaining, i would like to thank you for your work! :) I do use the glade version 3.22.1 and the most recent version of the gettext ruby gem. Within the project, i do use GetText::Tools::Task to define a rake task. In order to fetch various translation changes within the glade file.

# Somewhere within the rake file
require 'gettext/tools/task'
GetText::Tools::Task.define do |task|
  task.po_base_directory = 'po'
  task.mo_base_directory = 'locale'
  task.files = FileList['widgets/**/*.glade']
  task.domain = "test_domain"
end

All widgets, locales and po files are valid. When i run rake gettext:po:update to fetch changes within the glade file, i receive an error: widget is not glade-2.0 format..

The problem is located in file lib/gettext/tools/parser/glade.rb. gettext validates the gladefile, with two checks. The second check causes trouble. It assumes that the first two lines look like this (I copied it from gettext/samples/hello_glade2.glade):

<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">

I tried to open the sample file, with glade. But glade threw an error.
My glade file started with those lines:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->

Workaround

I simply added a second Regex to check if the second line starts with <!-- Generated with glade. And guess what, my po files are correctly updated and i do not receive errors anymore. I will attach the patch.

Meta task creation is difficult to extend

Hello,

We recently upgraded to gettext_i18n_rails version 1.0.1 and stumbled upon multiple problems introduced with the GetText::Tools:Task class, which I will list below.

The main issue is that there is no easy way to extend the mechanism that defines the domains. In our application we have multiple text domains.

In order to get the gettext:gettext:po:update task defined you have to create at least one domain using Gettext::Tools::Task.define. In our case we have to load the environment in order to see which domains we have to create. Unfortunately, there is no simple way to load the environment, intercept the rake chain and then call gettext:gettext:po:update.

In other words there is a circular dependency issue for multiple domains: you need to load the environment to create the domains and you can't load the environment (rake) unless you create a domain!

That's why in gettext_i18n_rails gem the first (only) domain is defined in class scope (breaks the circular dependency).

Another issue is that once you define a domain there is no easy way to remove it. For example we could create a dummy Gettext::Tools::Task, load the environment, add more domains and finally remove the dummy one. Unfortunately, this doesn't work either.

Instead of defining custom tasks using meta-programming I suggest we KISS it by using an array, adding domain / commands to it and then gettext:po:update simply executes the commands registered in the array (something like the command pattern). Task gettext:po:update should always be available and not only through Gettext::Tools::Task.define.

Generating PO/MO Files

I started a new Sinatra project that was based on a old Sinatra template which used Gettext for translation. There we had a Rake task to generate PO files and convert to MO and then use it.

I am very new to translation and might be missing out some thing. But what I think is when the versions change so did the structure of the lib.

How can I write a rake task that will generate the PO/MO files.

This is the rake task I am using and it gives and error:

require 'gettext'
require 'gettext/tools'

namespace :gettext do 

  desc "Update pot/po file"
  task :update_po do 

    location = File.expand_path('../../src/', File.dirname(__FILE__))

    files = nil
    Dir.chdir( location ) do 
      files = Dir.glob("{lib,helpers,views,routes}/**/*.{rb,rhtml,erb,slim}")
      files.concat( Dir.glob( "*.rb" ) )

      puts "Files selected are: "
      p files

      GetText.update_pofiles($project, files, "#{$project} #{$version}", po_root: 'i18n')
    end

  end

  desc "Make mo files from PO"
  task :make_mo do

  end

end

When running, I am getting this: NoMethodError: undefined methodupdate_pofiles' for GetText:Module`

Help is greatly appreciated.

gettext creates .mo files containing empty strings

I think I've traced this issue to gettext. When using rake gettext:pack, the resulting .mo files also contain untranslated strings, giving the translation as an empty string "". For example:

msgid "Untranslated"
msgstr ""

This should be shown as "Untranslated" in the locale, but instead we discovered that "" is returned.

I posted an issue agaiunst gettext_i18n_rails since I thought the view methods from that module were the issue: grosser/gettext_i18n_rails#81

Then I wrote a spec for fast_gettext (which gettext_i18n_rails uses) to make sure that _("Untranslated") indeed returns "Untranslated" and not "".

Lastly, I tried our own Spanish .po files, which have many blank msgstrs. I discovered that .mo files generated through the gettext:pack Rake task are larger than the ones generated e.g. by Poedit or by using msgfmt on the command line. The size increase is explained by gettext:pack including even empty strings. If you grep for any untranslated string in such a .mo file, you'll get a result, whereas it should return nothing (the untranslated string should not end up in the .mo file).

I tried to write a test for gettext to trace this further, but the gettext tests don't run green for me to begin with, so there's not much point. The fast_gettext specs ran fine for me, that's why I added some specs at that level instead of here.

What could be done about this? Since these three projects are so related, it's hard for me to find out where exactly one could add a test and change the behavior of the gettext:pack task.

The :pack task uses GetText.create_mo_files internally (and not much else).

Parsing error with `%i[a b]`

The parser seems to confuse %i[a b] (or %i(a b)) with a string. I am getting this error when running rake gettext:find:

Error parsing app/models/concerns/normalize_blank.rb:12
	       next unless %i[aa bb].include?(self.class.columns_hash[column].type)

 #<TypeError: no implicit conversion of Array into String> in
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/po_entry.rb:228:in `+'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/po_entry.rb:228:in `set_value'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:90:in `set_current_attribute'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:264:in `block in parse_source'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:57:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:242:in `parse_source'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:217:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/parser/ruby.rb:134:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:365:in `block in parse_path'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:360:in `each'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:360:in `parse_path'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:168:in `block in parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:166:in `each'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:166:in `parse'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:217:in `generate_pot'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:151:in `run'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/xgettext.rb:34:in `run'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/task.rb:330:in `xgettext'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/task.rb:314:in `create_pot'
/Users/renchap/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/gettext-3.2.3/lib/gettext/tools/task.rb:306:in `block in define_pot_file_task'

After debugging, in the set_value (https://github.com/ruby-gettext/gettext/blob/master/lib/gettext/po_entry.rb#L226) call I get value = [:aa, :bb].

I am not sure what is happening here, I guess the parser needs to take this syntax into account. %i has been introduced in Ruby 2.0.

Plural context with zero

It would be great if there were a way to specify a special plural form when the count is zero. Here's an example of my translation using i18n:

  login_count:
    one: Logged in once
    other: Logged in %{count} times
    zero: Never logged in

GetText::Tools::MsgInit limiting locale format due to Locale library

According to the gettext docs, a locale may include additional information after an @ symbol:

Some locale names use ll_CC.@variant instead of ll_CC. The @variant can denote any kind of characteristics that is not already implied by the language ll and the country CC. It can denote a particular monetary unit. For example, on glibc systems, de_DE@euro denotes the locale that uses the Euro currency, in contrast to the older locale de_DE which implies the use of the currency before 2002. It can also denote a dialect of the language, or the script used to write text (for example, ‘sr_RS@latin’ uses the Latin script, whereas ‘sr_RS’ uses the Cyrillic script to write Serbian), or the orthography rules, or similar.

The same functionality is supported by other translation tooling e.g. weblate, which seems to at least suggest it's not completely unheard of.

At work, we're using gettext in our application and have recently had to add more fine-grained locales to our product, e.g. en_GB@education, in order to specialise for a particular markets but we've hit an impasse with ruby-gettext via its use of the locale library because it effectively throws away any information after the secondary code.

Is there any reason why this can't be supported? Would you consider a patch for this?

rxgettext should split messages at newline characters

This bug is originally reported as Debian bug 726949.

I prepared a small revision of my test case, in order to show another
thing that I noticed about rxgettext:

  $ cat myapplication.rb
  #!/usr/bin/ruby
  # Copyright (C) 2012-2013 Francesco Poli
  #
  #  This program is free software; you can redistribute it and/or modify
  #  it under the terms of the GNU General Public License as published by
  #  the Free Software Foundation; either version 2 of the License, or
  #  (at your option) any later version.
  #
  #  This program is distributed in the hope that it will be useful,
  #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  #  GNU General Public License for more details.
  #
  #  You should have received a copy of the GNU General Public License with
  #  the Debian GNU/Linux distribution in file /usr/share/common-licenses/GPL;
  #  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
  #  Suite 330, Boston, MA  02111-1307  USA

  require 'gettext'
  include GetText
  GetText::bindtextdomain("myapplication")

  count = 0
  print _("Hello everybody!\n")
  count += 1

  print _("You are running an internationalized Ruby program.\n")
  count += 1

  # TRANSLATORS: %d is the number of already printed messages
  print _("You have already seen %d translatable messages.\n") % count

  print _("Is this message # 3 or # 4 ?\nDoes it matter?\n")

  print _("OK, I am tired...\n")

  print _("Goodbye!\n")

Let's use xgettext in order to generate the corresponding .pot file:

  $ xgettext --add-comments=TRANSLATORS --no-wrap \
             --copyright-holder="Francesco Poli" \
             --package-name=myapplication --package-version=0.2 \
             --msgid-bugs-address="[email protected]" \
             --language=python \
             myapplication.rb -o myapplication_XGETTEXT.pot
  $ cat myapplication_XGETTEXT.pot
  # SOME DESCRIPTIVE TITLE.
  # Copyright (C) YEAR Francesco Poli
  # This file is distributed under the same license as the PACKAGE package.
  # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
  #
  #, fuzzy
  msgid ""
  msgstr ""
  "Project-Id-Version: myapplication 0.2\n"
  "Report-Msgid-Bugs-To: [email protected]\n"
  "POT-Creation-Date: 2013-10-20 22:49+0200\n"
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  "Language-Team: LANGUAGE <[email protected]>\n"
  "Language: \n"
  "MIME-Version: 1.0\n"
  "Content-Type: text/plain; charset=CHARSET\n"
  "Content-Transfer-Encoding: 8bit\n"

  #: myapplication.rb:24
  msgid "Hello everybody!\n"
  msgstr ""

  #: myapplication.rb:27
  msgid "You are running an internationalized Ruby program.\n"
  msgstr ""

  #. TRANSLATORS: %d is the number of already printed messages
  #: myapplication.rb:31
  #, python-format
  msgid "You have already seen %d translatable messages.\n"
  msgstr ""

  #: myapplication.rb:33
  msgid ""
  "Is this message # 3 or # 4 ?\n"
  "Does it matter?\n"
  msgstr ""

  #: myapplication.rb:35
  msgid "OK, I am tired...\n"
  msgstr ""

  #: myapplication.rb:37
  msgid "Goodbye!\n"
  msgstr ""

As you can see the message at line 33 is split up into two strings for easier reading by translators. This is done since the message is actually intended to be printed onto two separate lines; so it makes sense that the translator has the opportunity to see it formatted in a way closer to how the program user will see it.

Unfortunately, rxgettext does not do the same:

  $ rxgettext --add-comments=TRANSLATORS --no-wrap \
              --copyright-holder="Francesco Poli" \
              --package-name=myapplication --package-version=0.2 \
              --msgid-bugs-address="[email protected]" \
              myapplication.rb -o myapplication_RXGETTEXT.pot
  $ cat myapplication_RXGETTEXT.pot
  # SOME DESCRIPTIVE TITLE.
  # Copyright (C) YEAR Francesco Poli
  # This file is distributed under the same license as the myapplication package.
  # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
  #
  #, fuzzy
  msgid ""
  msgstr ""
  "Project-Id-Version: myapplication 0.2\n"
  "Report-Msgid-Bugs-To: [email protected]\n"
  "POT-Creation-Date: 2013-10-20 23:01+0200\n"
  "PO-Revision-Date: 2013-10-20 23:01+0200\n"
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
  "Language-Team: LANGUAGE <[email protected]>\n"
  "Language: \n"
  "MIME-Version: 1.0\n"
  "Content-Type: text/plain; charset=UTF-8\n"
  "Content-Transfer-Encoding: 8bit\n"
  "Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"

  #: myapplication.rb:24
  msgid "Hello everybody!\n"
  msgstr ""

  #: myapplication.rb:27
  msgid "You are running an internationalized Ruby program.\n"
  msgstr ""

  #. TRANSLATORS: %d is the number of already printed messages
  #: myapplication.rb:31
  msgid "You have already seen %d translatable messages.\n"
  msgstr ""

  #: myapplication.rb:33
  msgid "Is this message # 3 or # 4 ?\nDoes it matter?\n"
  msgstr ""

  #: myapplication.rb:35
  msgid "OK, I am tired...\n"
  msgstr ""

  #: myapplication.rb:37
  msgid "Goodbye!\n"
  msgstr ""

I think it would far better, if rxgettext behaved like xgettext in this respect.

Please implement this feature and/or forward this bug report upstream.
Thanks for your time!

is Rails 6 supported?

Has anyone been able to use this with Rails 6?

I used this gem back in the days with Rails 1.
When I upgraded to Rails 4, I switch to FastGettext which now seems unmaintained and broken.

anyone else in a similar situation?

Or should I just convert my po files to rails yaml?

Fix the ruby-parser: `NoMethodError: undefined method `<<' for nil:NilClass`

Hello again! :)

I receive following Error NoMethodError: undefined method '<<' for nil:NilClass within the glade parser:

NoMethodError: undefined method `<<' for nil:NilClass
/home/mantel/repos/gettext/lib/gettext/tools/parser/ruby.rb:148:in `process_on_tstring_content'
/home/mantel/repos/gettext/lib/gettext/tools/parser/ruby.rb:234:in `block in on_default'
/home/mantel/repos/gettext/lib/gettext/tools/parser/ruby.rb:249:in `trace'
/home/mantel/repos/gettext/lib/gettext/tools/parser/ruby.rb:231:in `on_default'

This is the following line:

@string_stack.last << token.gsub(/\\./) do |data|

Here are some investigation notes:

  • @string_stack.last is nil
  • token is the content of a shell-call: echo hi

I will add a regression test.

Tutorial

Hello!

I found the tutorial link in README that doesn't work.

Do you have a working tutorial?

MsgMerge no-wrap option with linebreaks

I'm having issues with GetText::Tools::MsgMerge and the no-wrap option when working with content with linebreaks, for example this test fails:

    class TestNoWrapWithLineBrakes < self
      def po_content
        <<-'PO'
msgid "Line\nbreak"
msgstr "Line\nbreak"
        PO
      end

      def test_no_wrap
        @msgmerge.run("--update", "--no-wrap", @po_file_path, @po_file_path)
        assert_equal(<<-'PO', File.read(@po_file_path))
msgid "Line\nbreak"
msgstr "Line\nbreak"
        PO
      end
    end

Using GetText::Tools::MsgMerge returns:

msgid ""
"Line\n"
"brake"
msgstr ""
"Line\n"
"brake"

But from the command line:

$ msgmerge app.po app.po --update --no-wrap

We get... what we would expect:

msgid "Line\nbrake"
msgstr "Line\nbrake"

Question about detect_locales

In the detect_locales method, there's a regex that is used to determine whether a directory looks like a valid locale name.

This is useful for detecting the common case i.e. when a locale is a primary code (cs) or a primary code followed by a secondary code (cs_CZ) but when you have the character encoding e.g. cs_CZ.UTF-8 it fails to detect the locale.

Is there a rationale behind this choice?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.