1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-23 05:47:53 +00:00

separate server translation

This commit is contained in:
nishiki 2014-01-25 18:40:47 +01:00
parent d65316896e
commit 445626c7a2
4 changed files with 73 additions and 27 deletions

25
i18n/server/en.yml Normal file
View file

@ -0,0 +1,25 @@
---
en:
option:
usage: "Usage"
config: "Specifie the configuration file"
checkconfig: "Check the configuration"
setup: "Setup a new configuration file"
help: "Show this message help"
checkconfig:
fail: "Checkconfig failed:!"
empty: "ERROR: an importe option is missing!"
datadir: "ERROR: le data directory doesn't exist!"
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'
short: ! '%b %d'
custom: ! '%A, %M %B, %Y @ %l:%M%P'

25
i18n/server/fr.yml Normal file
View file

@ -0,0 +1,25 @@
---
fr:
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"
checkconfig:
fail: "Le fichier de configuration est invalide!"
empty: "ERREUR: Une option importante est manquante!"
datadir: "ERREUR: Le répertoire des données n'existe pas!"
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'
short: ! '%b %d'
custom: ! '%A, %M %B, %Y @ %l:%M%P'

View file

@ -261,37 +261,33 @@ class Server
@timeout = config['config']['timeout'].to_i
if @host.empty? || @port <= 0 || @data_dir.empty?
puts I18n.t('server.checkconfig.fail')
puts I18n.t('server.checkconfig.empty')
puts I18n.t('checkconfig.fail')
puts I18n.t('checkconfig.empty')
return false
end
if !Dir.exist?(@data_dir)
puts I18n.t('server.checkconfig.fail')
puts I18n.t('server.checkconfig.datadir')
puts I18n.t('checkconfig.fail')
puts I18n.t('checkconfig.datadir')
return false
end
if @log_file.nil? || @log_file.empty?
puts I18n.t('server.checkconfig.fail')
puts I18n.t('server.checkconfig.log_file_empty')
puts I18n.t('checkconfig.fail')
puts I18n.t('checkconfig.log_file_empty')
return false
#elsif !File.writable?(@log_file)
# puts I18n.t('server.checkconfig.fail')
# puts I18n.t('server.checkconfig.log_file_ro')
# return false
else
begin
@log = Logger.new(@log_file)
rescue
puts I18n.t('server.checkconfig.fail')
puts I18n.t('server.checkconfig.log_file_create')
puts I18n.t('checkconfig.fail')
puts I18n.t('checkconfig.log_file_create')
return false
end
end
rescue Exception => e
puts "#{I18n.t('server.checkconfig.fail')}\n#{e}"
puts "#{I18n.t('checkconfig.fail')}\n#{e}"
return false
end
@ -302,13 +298,13 @@ 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 I18n.t('form.setup.title')
puts '--------------------'
host = ask(I18n.t('server.form.setup.host')).to_s
port = ask(I18n.t('server.form.setup.port')).to_s
data_dir = ask(I18n.t('server.form.setup.data_dir')).to_s
log_file = ask(I18n.t('server.form.setup.log_file')).to_s
timeout = ask(I18n.t('server.form.setup.timeout')).to_s
host = ask(I18n.t('form.setup.host')).to_s
port = ask(I18n.t('form.setup.port')).to_s
data_dir = ask(I18n.t('form.setup.data_dir')).to_s
log_file = ask(I18n.t('form.setup.log_file')).to_s
timeout = ask(I18n.t('form.setup.timeout')).to_s
config = {'config' => {'host' => host,
'port' => port,
@ -321,7 +317,7 @@ class Server
file << config.to_yaml
end
rescue Exception => e
puts "#{I18n.t('server.form.setup.not_valid')}\n#{e}"
puts "#{I18n.t('form.setup.not_valid')}\n#{e}"
return false
end

View file

@ -15,34 +15,34 @@ 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.load_path = Dir["#{APP_ROOT}/i18n/server/*.yml"]
I18n.default_locale = :en
I18n.locale = lang.to_sym
options = {}
OptionParser.new do |opts|
opts.banner = "#{I18n.t('server.option.usage')}: mpw-server -c CONFIG [options]"
opts.banner = "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]"
opts.on("-c", "--config CONFIG", I18n.t('server.option.config')) do |config|
opts.on("-c", "--config CONFIG", I18n.t('option.config')) do |config|
options[:config] = config
end
opts.on("-t", "--checkconfig", I18n.t('server.option.checkconfig')) do |b|
opts.on("-t", "--checkconfig", I18n.t('option.checkconfig')) do |b|
options[:checkconfig] = b
end
opts.on("-s", "--setup", I18n.t('server.option.setup')) do |b|
opts.on("-s", "--setup", I18n.t('option.setup')) do |b|
options[:setup] = b
end
opts.on("-h", "--help", I18n.t('server.option.help')) do |b|
opts.on("-h", "--help", I18n.t('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]"
puts "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]"
exit 2
end