1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-27 07:33:05 +00:00

change method for default language

This commit is contained in:
nishiki 2013-12-30 22:14:29 +01:00
parent 787cdf0b50
commit 838e8f7563
4 changed files with 8 additions and 13 deletions

View file

@ -14,6 +14,8 @@ require "#{APP_ROOT}/lib/MPW.rb"
class Cli class Cli
# Constructor # Constructor
# @args: lang -> the operating system language
# config_file -> a specify config file
def initialize(lang, config_file=nil) def initialize(lang, config_file=nil)
@m = MPW.new(config_file) @m = MPW.new(config_file)

View file

@ -25,6 +25,7 @@ class MPW
attr_accessor :timeout_pwd attr_accessor :timeout_pwd
# Constructor # Constructor
# @args: file_config -> the specify config file
def initialize(file_config=nil) def initialize(file_config=nil)
@error_msg = nil @error_msg = nil
@file_config = "#{Dir.home()}/.mpw.cfg" @file_config = "#{Dir.home()}/.mpw.cfg"
@ -86,12 +87,7 @@ class MPW
return false return false
end end
if !@lang.nil? && !@lang.empty? I18n.locale = @lang.to_sym
if !File.exist?("#{APP_ROOT}/i18n/#{@lang}.yml")
@lang = 'en'
end
I18n.locale = @lang.to_sym
end
rescue Exception => e rescue Exception => e
@error_msg = "#{I18n.t('error.config.check')}\n#{e}" @error_msg = "#{I18n.t('error.config.check')}\n#{e}"

5
mpw
View file

@ -15,10 +15,9 @@ require "#{APP_ROOT}/lib/Cli.rb"
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1] lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
if !File.exist?("#{APP_ROOT}/i18n/#{lang}.yml") I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
lang = 'en'
end
I18n.load_path = Dir["#{APP_ROOT}/i18n/*.yml"] I18n.load_path = Dir["#{APP_ROOT}/i18n/*.yml"]
I18n.default_locale = :en
I18n.locale = lang.to_sym I18n.locale = lang.to_sym
options = {} options = {}

View file

@ -14,13 +14,11 @@ require "#{APP_ROOT}/lib/CliSSH.rb"
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1] lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
if !File.exist?("#{APP_ROOT}/i18n/#{lang}.yml") I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
lang = 'en'
end
I18n.load_path = Dir["#{APP_ROOT}/i18n/*.yml"] I18n.load_path = Dir["#{APP_ROOT}/i18n/*.yml"]
I18n.default_locale = :en
I18n.locale = lang.to_sym I18n.locale = lang.to_sym
options = {} options = {}
OptionParser.new do |opts| OptionParser.new do |opts|
opts.banner = "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]" opts.banner = "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]"