Redmine 4.1.1
This commit is contained in:
parent
33e7b881a5
commit
3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Redmine - project management software
|
||||
# Copyright (C) 2006-2017 Jean-Philippe Lang
|
||||
# Copyright (C) 2006-2019 Jean-Philippe Lang
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
@ -61,7 +63,7 @@ module Redmine
|
|||
# Localizes the given args with user's language
|
||||
def lu(user, *args)
|
||||
lang = user.try(:language).presence || Setting.default_language
|
||||
ll(lang, *args)
|
||||
ll(lang, *args)
|
||||
end
|
||||
|
||||
def format_date(date)
|
||||
|
@ -77,8 +79,7 @@ module Redmine
|
|||
options = {}
|
||||
options[:format] = (Setting.time_format.blank? ? :time : Setting.time_format)
|
||||
time = time.to_time if time.is_a?(String)
|
||||
zone = user.time_zone
|
||||
local = zone ? time.in_time_zone(zone) : (time.utc? ? time.localtime : time)
|
||||
local = user.convert_time_to_user_timezone(time)
|
||||
(include_date ? "#{format_date(local)} " : "") + ::I18n.l(local, options)
|
||||
end
|
||||
|
||||
|
@ -116,16 +117,18 @@ module Redmine
|
|||
# The result is cached to prevent from loading all translations files
|
||||
# unless :cache => false option is given
|
||||
def languages_options(options={})
|
||||
options = if options[:cache] == false
|
||||
valid_languages.
|
||||
select {|locale| ::I18n.exists?(:general_lang_name, locale)}.
|
||||
map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}.
|
||||
sort {|x,y| x.first <=> y.first }
|
||||
else
|
||||
ActionController::Base.cache_store.fetch "i18n/languages_options/#{Redmine::VERSION}" do
|
||||
languages_options :cache => false
|
||||
options =
|
||||
if options[:cache] == false
|
||||
available_locales = ::I18n.backend.available_locales
|
||||
valid_languages.
|
||||
select {|locale| available_locales.include?(locale)}.
|
||||
map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}.
|
||||
sort_by(&:first)
|
||||
else
|
||||
ActionController::Base.cache_store.fetch "i18n/languages_options/#{Redmine::VERSION}" do
|
||||
languages_options :cache => false
|
||||
end
|
||||
end
|
||||
end
|
||||
options.map {|name, lang| [name.force_encoding("UTF-8"), lang.force_encoding("UTF-8")]}
|
||||
end
|
||||
|
||||
|
@ -145,71 +148,17 @@ module Redmine
|
|||
end
|
||||
|
||||
# Custom backend based on I18n::Backend::Simple with the following changes:
|
||||
# * lazy loading of translation files
|
||||
# * available_locales are determined by looking at translation file names
|
||||
class Backend
|
||||
(class << self; self; end).class_eval { public :include }
|
||||
|
||||
class Backend < ::I18n::Backend::Simple
|
||||
module Implementation
|
||||
include ::I18n::Backend::Base
|
||||
include ::I18n::Backend::Pluralization
|
||||
|
||||
# Stores translations for the given locale in memory.
|
||||
# This uses a deep merge for the translations hash, so existing
|
||||
# translations will be overwritten by new ones only at the deepest
|
||||
# level of the hash.
|
||||
def store_translations(locale, data, options = {})
|
||||
locale = locale.to_sym
|
||||
translations[locale] ||= {}
|
||||
data = data.deep_symbolize_keys
|
||||
translations[locale].deep_merge!(data)
|
||||
end
|
||||
|
||||
# Get available locales from the translations filenames
|
||||
def available_locales
|
||||
@available_locales ||= ::I18n.load_path.map {|path| File.basename(path, '.*')}.uniq.sort.map(&:to_sym)
|
||||
end
|
||||
|
||||
# Clean up translations
|
||||
def reload!
|
||||
@translations = nil
|
||||
@available_locales = nil
|
||||
super
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def init_translations(locale)
|
||||
locale = locale.to_s
|
||||
paths = ::I18n.load_path.select {|path| File.basename(path, '.*') == locale}
|
||||
load_translations(paths)
|
||||
translations[locale] ||= {}
|
||||
end
|
||||
|
||||
def translations
|
||||
@translations ||= {}
|
||||
end
|
||||
|
||||
# Looks up a translation from the translations hash. Returns nil if
|
||||
# eiher key is nil, or locale, scope or key do not exist as a key in the
|
||||
# nested translations hash. Splits keys or scopes containing dots
|
||||
# into multiple keys, i.e. <tt>currency.format</tt> is regarded the same as
|
||||
# <tt>%w(currency format)</tt>.
|
||||
def lookup(locale, key, scope = [], options = {})
|
||||
init_translations(locale) unless translations.key?(locale)
|
||||
keys = ::I18n.normalize_keys(locale, key, scope, options[:separator])
|
||||
|
||||
keys.inject(translations) do |result, _key|
|
||||
_key = _key.to_sym
|
||||
return nil unless result.is_a?(Hash) && result.has_key?(_key)
|
||||
result = result[_key]
|
||||
result = resolve(locale, _key, result, options.merge(:scope => nil)) if result.is_a?(Symbol)
|
||||
result
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include Implementation
|
||||
# Adds fallback to default locale for untranslated strings
|
||||
include ::I18n::Backend::Fallbacks
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue