From 1a9fb0795053c7a03979e1991f70ecb5353b244c Mon Sep 17 00:00:00 2001 From: nishiki Date: Wed, 15 Jan 2014 23:09:57 +0100 Subject: [PATCH] translate Sync.rb --- i18n/en.yml | 4 ++++ i18n/fr.yml | 4 ++++ lib/Sync.rb | 35 ++++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/i18n/en.yml b/i18n/en.yml index a3141bf..76bce2a 100644 --- a/i18n/en.yml +++ b/i18n/en.yml @@ -17,6 +17,10 @@ en: read: "Can't import, unable to read %{file}!" update: name_empty: "You must define a name!" + sync: + no_data: "Nothing data!" + not_authorized: "You haven't the access to remote file!" + unknown: "An unknown error is occured!" cli: option: usage: "Usage" diff --git a/i18n/fr.yml b/i18n/fr.yml index 5ccef5f..aa847ed 100644 --- a/i18n/fr.yml +++ b/i18n/fr.yml @@ -17,6 +17,10 @@ fr: read: "Impossible d'importer le fichier %{file}, car il n'est pas lisible!" update: name_empty: "Vous devez définir un nom!" + sync: + no_data: "Aucune data!" + not_authorized: "Vous n'avez pas les autorisations d'accès au fichier distant!" + unknown: "Une erreur inconnue est survenue!" cli: option: usage: "Utilisation" diff --git a/lib/Sync.rb b/lib/Sync.rb index 126b02d..72743a3 100644 --- a/lib/Sync.rb +++ b/lib/Sync.rb @@ -14,30 +14,42 @@ class Sync attr_accessor :error_msg + # Constructor def initialize() @error_msg = nil end + # Disable the sync def disable() @sync = false end + # Connect to server + # @args: host -> the server host + # port -> ther connection port + # gpg_key -> the gpg key + # password -> the remote password + # suffix -> the suffix file + # @rtrn: false if the connection fail def connect(host, port, gpg_key, password, suffix=nil) - @gpg_key = gpg_key - @password = password - @suffix = suffix + @gpg_key = gpg_key + @password = password + @suffix = suffix begin @socket= TCPSocket.new(host, port) @sync = true rescue Exception => e - @error_msg = "ERROR: Connection impossible\n#{e}" + @error_msg = "#{I18n.t('error.sync.connection')}\n#{e}" @sync = false end return @sync end + # Get data on server + # @args: gpg_password -> the gpg password + # @rtrn: nil if nothing data or error def get(gpg_password) if !@sync return nil @@ -51,6 +63,7 @@ class Sync @socket.puts send_msg.to_json msg = JSON.parse(@socket.gets) + puts msg case msg['error'] when nil, 'file_not_exist' tmp_file = "/tmp/mpw-#{MPW.generatePassword()}.gpg" @@ -67,14 +80,17 @@ class Sync return @mpw.search() when 'not_authorized' - @error_msg = 'not authorized' + @error_msg = "#{I18n.t('error.sync.not_authorized')}\n#{e}" else - @error_msg = 'error unknow' + @error_msg = "#{I18n.t('error.sync.unknown')}\n#{e}" end return nil end + # Update the remote data + # @args: data -> the data to send on server + # @rtrn: false if there is a problem def update(data) if !@sync return true @@ -93,11 +109,11 @@ class Sync when nil return true when 'not_authorized' - @error_msg = 'not authorized' + @error_msg = "#{I18n.t('error.sync.not_authorized')}\n#{e}" when 'no_data' - @error_msg = 'no data' + @error_msg = "#{I18n.t('error.sync.no_data')}\n#{e}" else - @error_msg = 'error unknow' + @error_msg = "#{I18n.t('error.sync.unknown')}\n#{e}" end return false @@ -106,6 +122,7 @@ class Sync def delete() end + # Close the connection def close() if !@sync return