Project

General

Profile

Defect #42815 » 0002-Drop-Redmine-I18n-Backend.new-custom-backend.patch

Marius BĂLTEANU, 2025-06-02 21:55

View differences:

config/application.rb
config.i18n.enforce_available_locales = true
config.i18n.fallbacks = true
config.i18n.default_locale = 'en'
config.i18n.available_locales = Dir[Rails.root / 'config' / 'locales' / '*.yml'].map { |f| File.basename(f, '.yml').to_sym }
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
config/initializers/30-redmine.rb
require 'redmine/plugin_loader'
Rails.application.config.to_prepare do
I18n.backend = Redmine::I18n::Backend.new
# Forces I18n to load available locales from the backend
I18n.config.available_locales = nil
I18n::Backend::Simple.include(I18n::Backend::Pluralization)
# Use Nokogiri as XML backend instead of Rexml
ActiveSupport::XmlMini.backend = 'Nokogiri'
lib/redmine/i18n.rb
def current_language
::I18n.locale
end
# Custom backend based on I18n::Backend::Simple with the following changes:
# * available_locales are determined by looking at translation file names
class Backend < ::I18n::Backend::Simple
# Get available locales from the translations filenames
def available_locales
@available_locales ||= begin
redmine_locales = Dir[Rails.root / 'config' / 'locales' / '*.yml'].map { |f| File.basename(f, '.yml').to_sym }
super & redmine_locales
end
end
# Adds custom pluralization rules
include ::I18n::Backend::Pluralization
# Adds fallback to default locale for untranslated strings
include ::I18n::Backend::Fallbacks
end
end
end
(2-2/2)