From b1c281f3186d32bd94fc21b0415c6366addcfd84 Mon Sep 17 00:00:00 2001 From: nishiki Date: Sat, 1 Feb 2014 20:17:55 +0100 Subject: [PATCH] fix I18n.enforce_available_locales --- mpw | 16 ++++++++++++++++ mpw-server | 19 ++++++++++++++++++- mpw-ssh | 16 ++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/mpw b/mpw index e5cf0a3..ebe9f2a 100755 --- a/mpw +++ b/mpw @@ -13,13 +13,25 @@ APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath) require "#{APP_ROOT}/MPW/UI/Cli" require "#{APP_ROOT}/MPW/Config" +# --------------------------------------------------------- # +# Set local +# --------------------------------------------------------- # + lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1] +if defined? I18n.enforce_available_locales + I18n.enforce_available_locales = true +end + I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) I18n.load_path = Dir["#{APP_ROOT}/i18n/cli/*.yml"] I18n.default_locale = :en I18n.locale = lang.to_sym +# --------------------------------------------------------- # +# Options +# --------------------------------------------------------- # + options = {} options[:force] = false options[:format] = false @@ -93,6 +105,10 @@ OptionParser.new do |opts| end end.parse! +# --------------------------------------------------------- # +# Main +# --------------------------------------------------------- # + config = MPW::Config.new(options[:config]) check_error = config.checkconfig() diff --git a/mpw-server b/mpw-server index 07b42f5..d1f5192 100755 --- a/mpw-server +++ b/mpw-server @@ -12,13 +12,25 @@ require 'i18n' APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath) require "#{APP_ROOT}/lib/Server.rb" +# --------------------------------------------------------- # +# Set local +# --------------------------------------------------------- # + lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1] +if defined? I18n.enforce_available_locales + I18n.enforce_available_locales = true +end + I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) I18n.load_path = Dir["#{APP_ROOT}/i18n/server/*.yml"] I18n.default_locale = :en I18n.locale = lang.to_sym +# --------------------------------------------------------- # +# Options +# --------------------------------------------------------- # + options = {} OptionParser.new do |opts| opts.banner = "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]" @@ -41,6 +53,10 @@ OptionParser.new do |opts| end end.parse! +# --------------------------------------------------------- # +# Main +# --------------------------------------------------------- # + if options[:config].nil? || options[:config].empty? puts "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]" exit 2 @@ -54,8 +70,9 @@ elsif options[:setup] server.setup(options[:config]) else if server.checkconfig(options[:config]) - server.start() + server.start end end +server = nil exit 0 diff --git a/mpw-ssh b/mpw-ssh index 9ba3791..f90cc81 100755 --- a/mpw-ssh +++ b/mpw-ssh @@ -15,11 +15,23 @@ require "#{APP_ROOT}/MPW/Config" lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1] +# --------------------------------------------------------- # +# Set local +# --------------------------------------------------------- # + +if defined? I18n.enforce_available_locales + I18n.enforce_available_locales = true +end + I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) I18n.load_path = Dir["#{APP_ROOT}/i18n/cli/*.yml"] I18n.default_locale = :en I18n.locale = lang.to_sym +# --------------------------------------------------------- # +# Options +# --------------------------------------------------------- # + options = {} OptionParser.new do |opts| opts.banner = "#{I18n.t('ssh.option.usage')}: mpw-ssh SEARCH [options]" @@ -46,6 +58,10 @@ OptionParser.new do |opts| end end.parse! +# --------------------------------------------------------- # +# Main +# --------------------------------------------------------- # + config = MPW::Config.new(options[:config]) check_error = config.checkconfig()