diff --git a/lib/Cli.rb b/lib/Cli.rb index 136cba1..2b53ab3 100644 --- a/lib/Cli.rb +++ b/lib/Cli.rb @@ -14,6 +14,8 @@ require "#{APP_ROOT}/lib/MPW.rb" class Cli # Constructor + # @args: lang -> the operating system language + # config_file -> a specify config file def initialize(lang, config_file=nil) @m = MPW.new(config_file) diff --git a/lib/MPW.rb b/lib/MPW.rb index e4c2fd3..d0588d7 100644 --- a/lib/MPW.rb +++ b/lib/MPW.rb @@ -25,6 +25,7 @@ class MPW attr_accessor :timeout_pwd # Constructor + # @args: file_config -> the specify config file def initialize(file_config=nil) @error_msg = nil @file_config = "#{Dir.home()}/.mpw.cfg" @@ -86,12 +87,7 @@ class MPW return false end - if !@lang.nil? && !@lang.empty? - if !File.exist?("#{APP_ROOT}/i18n/#{@lang}.yml") - @lang = 'en' - end - I18n.locale = @lang.to_sym - end + I18n.locale = @lang.to_sym rescue Exception => e @error_msg = "#{I18n.t('error.config.check')}\n#{e}" diff --git a/mpw b/mpw index 2aacb50..a06fd40 100755 --- a/mpw +++ b/mpw @@ -15,10 +15,9 @@ require "#{APP_ROOT}/lib/Cli.rb" lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1] -if !File.exist?("#{APP_ROOT}/i18n/#{lang}.yml") - lang = 'en' -end +I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) I18n.load_path = Dir["#{APP_ROOT}/i18n/*.yml"] +I18n.default_locale = :en I18n.locale = lang.to_sym options = {} diff --git a/mpw-ssh b/mpw-ssh index a67e134..a991cc1 100755 --- a/mpw-ssh +++ b/mpw-ssh @@ -14,13 +14,11 @@ require "#{APP_ROOT}/lib/CliSSH.rb" lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1] -if !File.exist?("#{APP_ROOT}/i18n/#{lang}.yml") - lang = 'en' -end +I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) I18n.load_path = Dir["#{APP_ROOT}/i18n/*.yml"] +I18n.default_locale = :en I18n.locale = lang.to_sym - options = {} OptionParser.new do |opts| opts.banner = "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]"