Fixed --include-untranslated handling. Before even untranslated keys were included if a formatter didn't return nil als fallback language (which would have caused a crash).
This commit is contained in:
parent
13a28890cf
commit
ef1e684824
3 changed files with 12 additions and 10 deletions
|
@ -117,8 +117,8 @@ module Twine
|
|||
@options[:developer_language] || @strings.language_codes[0]
|
||||
end
|
||||
|
||||
def fallback_language(lang)
|
||||
default_language
|
||||
def fallback_languages(lang)
|
||||
[default_language]
|
||||
end
|
||||
|
||||
def format_file(lang)
|
||||
|
@ -156,9 +156,9 @@ module Twine
|
|||
end
|
||||
|
||||
def format_row(row, lang)
|
||||
value = row.translated_string_for_lang(lang, fallback_language(lang))
|
||||
value = row.translated_string_for_lang(lang)
|
||||
if value.nil? && @options[:include_untranslated]
|
||||
value = row.translated_string_for_lang(default_language)
|
||||
value = row.translated_string_for_lang(fallback_languages(lang))
|
||||
end
|
||||
return nil unless value
|
||||
|
||||
|
|
|
@ -91,8 +91,8 @@ module Twine
|
|||
end
|
||||
end
|
||||
|
||||
def fallback_language(lang)
|
||||
DEFAULT_LANG_CODES[lang] || super
|
||||
def fallback_languages(lang)
|
||||
[DEFAULT_LANG_CODES[lang], super].flatten.compact
|
||||
end
|
||||
|
||||
def format_header(lang)
|
||||
|
|
|
@ -41,16 +41,18 @@ module Twine
|
|||
end
|
||||
|
||||
def translated_string_for_lang(lang, default_lang=nil)
|
||||
if @translations[lang]
|
||||
return @translations[lang]
|
||||
elsif default_lang.respond_to?("each")
|
||||
translation = [lang].flatten.map { |l| @translations[l] }.first
|
||||
return translation if translation
|
||||
|
||||
# TODO: get rid of all this and the default_lang parameter once all formatters are converted to the new style
|
||||
if default_lang.respond_to?("each")
|
||||
default_lang.each do |def_lang|
|
||||
if @translations[def_lang]
|
||||
return @translations[def_lang]
|
||||
end
|
||||
end
|
||||
return nil
|
||||
else
|
||||
elsif default_lang
|
||||
return @translations[default_lang]
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue