diff --git a/i18n/en.yml b/i18n/en.yml index 6eecd3c..27a2d11 100644 --- a/i18n/en.yml +++ b/i18n/en.yml @@ -111,6 +111,21 @@ en: display: connect: "Connection to:" nothing: "Nothing result!" + server: + option: + usage: "Usage" + config: "Specifie the configuration file" + checkconfig: "Check the configuration" + setup: "Setup a new configuration file" + help: "Show this message help" + form: + setup: + title: "Serveur configuration" + host: "IP listen: " + port: "Port listen: " + data_dir: "Data directory: " + timeout: "Timeout to second: " + not_valid: "ERROR: Impossible to write the configuration file!" formats: default: ! '%Y-%m-%d' long: ! '%B %d, %Y' diff --git a/i18n/fr.yml b/i18n/fr.yml index ba433fb..770dd21 100644 --- a/i18n/fr.yml +++ b/i18n/fr.yml @@ -111,6 +111,21 @@ fr: display: connect: "Connexion à:" nothing: "Aucun résultat!" + server: + option: + usage: "Utilisation" + config: "Spécifie le fichier de configuration" + checkconfig: "Vérifie le fichier de configuration" + setup: "Permet de générer un nouveau fichier de configuration" + help: "Affiche ce message d'aide" + form: + setup: + title: "Configuration du serveur" + host: "IP d'écoute: " + port: "Port d'écoute: " + data_dir: "Répertoire des données: " + timeout: "Timeout en seconde: " + not_valid: "ERREUR: Impossible d'écire le fichier de configuration!" formats: default: ! '%Y-%m-%d' long: ! '%B %d, %Y' diff --git a/lib/Server.rb b/lib/Server.rb index b90a5f5..77ee2c2 100644 --- a/lib/Server.rb +++ b/lib/Server.rb @@ -260,7 +260,6 @@ class Server # @args: file_config -> the configuration file # @rtrn: true if le config file is create def setup(file_config) - puts I18n.t('server.form.setup.title') puts '--------------------' host = ask(I18n.t('server.form.setup.host')).to_s @@ -278,7 +277,7 @@ class Server file << config.to_yaml end rescue Exception => e - @error_msg = "Can't write the config file!\n#{e}" + puts "#{I18n.t('server.formsetup.not_valid')}\n#{e}" return false end diff --git a/mpw-server b/mpw-server index f764037..3143b59 100755 --- a/mpw-server +++ b/mpw-server @@ -6,32 +6,46 @@ require 'rubygems' require 'optparse' require 'pathname' +require 'locale' +require 'i18n' APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath) require "#{APP_ROOT}/lib/Server.rb" +lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1] + +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 = "Usage: mpw-server -c CONFIG [options]" + opts.banner = "#{I18n.t('server.option.usage')}: mpw-server -c CONFIG [options]" - opts.on("-c", "--config CONFIG", "Specifie the configuration file") do |config| + opts.on("-c", "--config CONFIG", I18n.t('server.option.config')) do |config| options[:config] = config end - opts.on("-t", "--check-config", "Check your configuration") do |b| + opts.on("-t", "--checkconfig", I18n.t('server.option.checkconfig')) do |b| options[:checkconfig] = b end - opts.on("-s", "--setup", "Force a server") do |b| + opts.on("-s", "--setup", I18n.t('server.option.setup')) do |b| options[:setup] = b end - opts.on("-h", "--help", "Show this message") do |b| + opts.on("-h", "--help", I18n.t('server.option.help')) do |b| puts opts exit 0 end end.parse! +if options[:config].nil? || options[:config].empty? + puts "#{I18n.t('server.option.usage')}: mpw-server -c CONFIG [options]" + exit 2 +end + server = Server.new if options[:checkconfig]