correct location for language files in redmine plugins

Added by ciaran jessup over 8 years ago

Hi folks, everywhere I look it seems that the suggested place to put the language files for plugins is both in <plugin_name>/lang and <plugin_name>/config/locales to allow forward+backward compatibility. however when I look through the redmine code (plugin.rb) it seems as though plugins should have their l18n fils in <plugin_name>/locales. When I put my l18n files in this location they do being to be used, but is this correct, or have I missed something ?

Replies (5)

RE: correct location for language files in redmine plugins - Added by ciaran jessup over 8 years ago

ciaran jessup wrote:

Hi folks, everywhere I look it seems that the suggested place to put the language files for plugins is both in <plugin_name>/lang and <plugin_name>/config/locales to allow forward+backward compatibility. however when I look through the redmine code (plugin.rb) it seems as though plugins should have their l18n fils in <plugin_name>/locales. When I put my l18n files in this location they do being to be used, but is this correct, or have I missed something ?

Just to be clear, I mean located in <plugin_name>/locales rather than <p[ugin_name>/config/locales. <plugin_name>/lang is fine for backwards compatibility :)

RE: correct location for language files in redmine plugins - Added by Mischa The Evil over 8 years ago

ciaran jessup wrote:

ciaran jessup wrote:

Hi folks, everywhere I look it seems that the suggested place to put the language files for plugins is both in <plugin_name>/lang and <plugin_name>/config/locales to allow forward+backward compatibility. however when I look through the redmine code (plugin.rb) it seems as though plugins should have their l18n fils in <plugin_name>/locales. When I put my l18n files in this location they do being to be used, but is this correct, or have I missed something ?

Just to be clear, I mean located in <plugin_name>/locales rather than <p[ugin_name>/config/locales. <plugin_name>/lang is fine for backwards compatibility :)

When I look at the plugin constructor at source:/trunk/lib/redmine/plugin.rb#L64 it needs to be <plugin_name>/config/locales:

   # Plugin constructor
    def self.register(id, &block)
      p = new(id)
      p.instance_eval(&block)
      # Set a default name if it was not provided during registration
      p.name(id.to_s.humanize) if p.name.nil?
      # Adds plugin locales if any
      # YAML translation files should be found under <plugin>/config/locales/
      ::I18n.load_path += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', id.to_s, 'config', 'locales', '*.yml'))
      registered_plugins[id] = p
    end

RE: correct location for language files in redmine plugins - Added by ciaran jessup over 8 years ago

I don't really know how any of this stuff wires together, but it seems to me that this code might be coming into play:

http://www.redmine.org/projects/redmine/repository/entry/trunk/vendor/plugins/engines/lib/engines/plugin.rb#L97

??

RE: correct location for language files in redmine plugins - Added by ciaran jessup over 8 years ago

Whilst I've got someone's attention ;) Currently I'm trying to extract some plugins that have been built into a redmine source-base (the SA agile plugins) one thing that these plugins do is override the existing localisation values (for example renaming 'issue' to 'ticket' and 'version' to 'sprint'.

As it stands currently, I don't think its possible for plugins to override pre-existing l18n configuration files. If a change was made to engines/lib/engines/plugin.rb add_plugin_locale_paths method so that it added the plugin's locale file to the end of the load_path rather than the start of the plugins' locale paths within the array then I believe the plugins can be setup to override the default provide l18n files, an example method would possibly look like this:

    def add_plugin_locale_paths
      locale_path = File.join(directory, 'locales')
      return unless File.exists?(locale_path)

      locale_files = Dir[File.join(locale_path, '*.{rb,yml}')]
      return if locale_files.blank?

      I18n.load_path.push(*locale_files)
    end

I can throw this into my git fork and submit a pull-request to edavis10 if required?

RE: correct location for language files in redmine plugins - Added by Mischa The Evil over 8 years ago

Ciaran,

Sorry for my slow response but it has been pretty busy as usual... It seems to me a neat feature if Redmine plugin authors could modify the core's I18n-strings.
I'd suggest to open-up a new issue for the descriped issue [ sic ] other members can comment and Redmine lead can take "position". :)

You wrote:

I can throw this into my git fork and submit a pull-request to edavis10 if required?

If you do Eric likes to have the changes seperated in a branch per feature... :wink:

Regards,

Mischa.

(1-5/5)