Skip to content

Commit

Permalink
i18n - return default locale when current language is not set
Browse files Browse the repository at this point in the history
to avoid reinitialization in testsuite
  • Loading branch information
Ladislav Slezak committed May 24, 2013
1 parent abf3c32 commit f08bd70
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/ruby/ycp/i18n.rb
Expand Up @@ -7,6 +7,7 @@ module ClassMethods

#TODO load alternative in development recent translation
LOCALE_DIR = "/usr/share/YaST2/locale"
DEFAULT_LOCALE = "en_US"

def textdomain domain
# TODO FIXME:
Expand Down Expand Up @@ -54,7 +55,7 @@ def combined_repositories
def available_locales
# the first item is used as the fallback
# when the requested locale is not available
locales = [ "en_US" ]
locales = [ DEFAULT_LOCALE ]

Dir["#{LOCALE_DIR}/*"].each do |f|
locale_name = File.basename f
Expand All @@ -69,6 +70,8 @@ def current_language
# like ".UTF-8" if present)
lang = WFM.GetLanguage.gsub(/\..*$/, "")

return DEFAULT_LOCALE if lang.empty?

# remove the country suffix if that locale is not available
# e.g. there are "pt_BR" and "de" translations (there is generic "pt" but no "de_DE")
lang.gsub!(/_.*$/, "") if FastGettext.available_locales.nil? || !FastGettext.available_locales.include?(lang)
Expand Down

0 comments on commit f08bd70

Please sign in to comment.