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

Problems with multiple domains setup #176

Open
MamesPalmero opened this issue Aug 7, 2018 · 7 comments
Open

Problems with multiple domains setup #176

MamesPalmero opened this issue Aug 7, 2018 · 7 comments

Comments

@MamesPalmero
Copy link

I am trying to configure gettext_i18n_rails to use multiple domains, as it says in the configuration. Here is my current configuration:

config/initializers/fast_gettext.rb

FastGettext.add_text_domain 'app', path: 'locale', type: :po
FastGettext.add_text_domain 'errors', path: 'locale', type: :po
FastGettext.default_available_locales = ['en', 'es'']
FastGettext.default_text_domain = 'app'

Object.send(:include, FastGettext::TranslationMultidomain)

lib/task/gettext.rake

Rake::Task["gettext:setup"].clear

namespace :gettext do
  task :setup => [:environment] do
    FastGettext.translation_repositories.each_key do |domain|
      GetText::Tools::Task.define do |task|
        task.package_name = domain
        task.package_version = "1.0.0"
        task.domain = domain
        task.po_base_directory = locale_path
        task.mo_base_directory = locale_path
        task.files = files_to_translate
        task.enable_description = false
        task.msgmerge_options = gettext_msgmerge_options
        task.msgcat_options = gettext_msgcat_options
        task.xgettext_options = gettext_xgettext_options
      end
    end
  end
end

and in any file of my project app/.../*.rb
d_("errors", "Error")

The problem is that after adding the languages and executing rake gettext: find, the .pot and .po files are generated empty. I think the locale/errors.pot andlocale/language/errors.po files should have an entry with msgid 'error" . Is there something wrong with my configuration or something that I did not understand correctly?

@grosser
Copy link
Owner

grosser commented Aug 8, 2018 via email

@jstoup111
Copy link

I've got the same issue and tried to follow the code as much as I could before I started getting lost. I am assuming that the parser (based on my research) isn't including the multidomain methods that are used to translate. I'm happy to open a PR if I can be pointed in the right direction. I'm not sure it's even this gem that needs to be updated to support it.

@grosser
Copy link
Owner

grosser commented Nov 14, 2018

sorry no idea ... just erm dig in and add docs / refactor things that are unclear on the way :(

@yorickpeterse
Copy link

yorickpeterse commented Jan 3, 2019

It seems the problem is in lib/gettext_i18n_rails/ruby_gettext_extractor.rb, specifically in the method process_call:

def process_call exp
  _call = exp.shift
  _recv = process exp.shift
  meth  = exp.shift
                                    
  case meth
  when :_, :p_, :N_, :pgettext, :s_
    gettext_simple_call(exp)
  when :n_
    gettext_plural_call(exp)
  end
                                    
  until exp.empty? do
    process(exp.shift)
  end
                                    
  s()
end

This method seems to specifically ignore calls such as d_(), D_(), etc. Take this file for example:

_('foo')
D_('bar')

The above code will only find the first translation. If you change it to the following:

def process_call exp
  _call = exp.shift
  _recv = process exp.shift
  meth  = exp.shift
                                              
  case meth
  when :_, :p_, :N_, :pgettext, :s_, :d_, :D_
    gettext_simple_call(exp)
  when :n_
    gettext_plural_call(exp)
  end
                                              
  until exp.empty? do
    process(exp.shift)
  end
                                              
  s()
end

It will find both, producing:

[["foo", "/tmp/test.rb:1"], ["bar", "/tmp/test.rb:2"]]

Having said that, I'm not sure if this output is what is expected when using multi domain translation strings.

@grosser
Copy link
Owner

grosser commented Jan 3, 2019

I don't remember touching / seeing this ... can you make a PR with the change you think is best 🤷‍♂️
(ideally not breaking anything else :D )

@yorickpeterse
Copy link

@grosser Unfortunately, I'm not sure if these changes would even be correct as I'm not familiar with what output is expected by the code that makes use of the above code.

@grosser
Copy link
Owner

grosser commented Jan 3, 2019

can you come up with a test-case that fails now ? ... so we have something concrete that can be fixed by poking in the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants