From 2636e963e5756bd5dd464088fdd052a50e328b6a Mon Sep 17 00:00:00 2001 From: Jonathan PHILIPPE Date: Wed, 28 Aug 2024 18:38:13 +0200 Subject: [PATCH] Translates letter --- epics.gemspec | 1 + lib/epics.rb | 4 + lib/epics/client.rb | 9 +- lib/epics/letter_renderer.rb | 22 ++++ lib/letter/ini.erb | 201 ++++++++++++++++++----------------- lib/letter/locales/de.yml | 12 +++ lib/letter/locales/en.yml | 12 +++ lib/letter/locales/fr.yml | 12 +++ 8 files changed, 171 insertions(+), 102 deletions(-) create mode 100644 lib/epics/letter_renderer.rb create mode 100644 lib/letter/locales/de.yml create mode 100644 lib/letter/locales/en.yml create mode 100644 lib/letter/locales/fr.yml diff --git a/epics.gemspec b/epics.gemspec index 8fd1a2a..8a481e2 100644 --- a/epics.gemspec +++ b/epics.gemspec @@ -41,6 +41,7 @@ Gem::Specification.new do |spec| spec.post_install_message += "\e[32m" + ('*' * 60) + "\n\e[0m" spec.add_dependency 'faraday', '>= 1.10.0' + spec.add_dependency 'i18n', '>= 1.1.0' spec.add_dependency 'nokogiri', '>= 1.16.5' spec.add_dependency 'rubyzip', '>= 2.3.2' spec.add_dependency 'rexml', '>= 3.2.8' diff --git a/lib/epics.rb b/lib/epics.rb index e8fc3df..2376cd5 100644 --- a/lib/epics.rb +++ b/lib/epics.rb @@ -1,6 +1,7 @@ require 'openssl' require 'base64' require 'erb' +require 'i18n' require 'json' require 'zlib' require 'zip' @@ -12,6 +13,7 @@ require "epics/key" require "epics/response" require "epics/error" +require 'epics/letter_renderer' require "epics/middleware/xmlsig" require "epics/middleware/parse_ebics" require "epics/generic_request" @@ -52,6 +54,8 @@ require "epics/signer" require "epics/client" +I18n.load_path += Dir[File.join(File.dirname(__FILE__), 'letter/locales', '*.yml')] + module Epics end diff --git a/lib/epics/client.rb b/lib/epics/client.rb index 904959f..deda7c3 100644 --- a/lib/epics/client.rb +++ b/lib/epics/client.rb @@ -3,6 +3,7 @@ class Epics::Client attr_accessor :passphrase, :url, :host_id, :user_id, :partner_id, :keys, :keys_content attr_writer :iban, :bic, :name + attr_accessor :locale def_delegators :connection, :post @@ -14,6 +15,7 @@ def initialize(keys_content, passphrase, url, host_id, user_id, partner_id) self.host_id = host_id self.user_id = user_id self.partner_id = partner_id + self.locale = :de end def inspect @@ -68,9 +70,12 @@ def self.setup(passphrase, url, host_id, user_id, partner_id, keysize = 2048) client end + def letter_renderer + @letter_renderer ||= Epics::LetterRenderer.new(self) + end + def ini_letter(bankname) - raw = File.read(File.join(File.dirname(__FILE__), '../letter/', 'ini.erb')) - ERB.new(raw).result(binding) + letter_renderer.render(bankname) end def save_ini_letter(bankname, path) diff --git a/lib/epics/letter_renderer.rb b/lib/epics/letter_renderer.rb new file mode 100644 index 0000000..75424d6 --- /dev/null +++ b/lib/epics/letter_renderer.rb @@ -0,0 +1,22 @@ +class Epics::LetterRenderer + extend Forwardable + + TEMPLATE_PATH = File.join(File.dirname(__FILE__), '../letter/', 'ini.erb') + I18N_SCOPE = 'epics.letter' + + def initialize(client) + @client = client + end + + def translate(key) + I18n.translate(key, locale: @client.locale, scope: I18N_SCOPE) + end + + alias_method :t, :translate + + def_delegators :@client, :user_id, :partner_id, :a, :x, :e + + def render(bankname) + ERB.new(File.read(TEMPLATE_PATH)).result(binding) + end +end diff --git a/lib/letter/ini.erb b/lib/letter/ini.erb index eefc344..878d0a1 100644 --- a/lib/letter/ini.erb +++ b/lib/letter/ini.erb @@ -4,30 +4,41 @@ EBICS ini +
-

EBICS-Initialisierungsbrief (INI)

+

<%= t('initialization_letter.a') %>

- Datum + <%= t('date') %> - <%= Date.today.strftime("%d.%m.%Y") %> + <%= Date.today.strftime('%d.%m.%Y') %>
- Uhrzeit + <%= t('time') %> - <%= Time.now.strftime("%H:%M:%S") %> + <%= Time.now.strftime('%H:%M:%S') %>
- Empfänger + <%= t('recipient') %> <%= bankname %> @@ -43,129 +54,123 @@
- Kunden-ID + Partner-ID <%= partner_id %>
-

Öffentlicher Schlüssel für die elektronische Unterschrift (A006)

+

<%= t('certificate_type') %> : A006

Exponent (<%= a.key.e.num_bytes * 8 %> Bit):

-

<%= a.e %>

+

<%= a.e %>

Modulus (<%= a.key.n.num_bytes * 8 %> Bit):

-

<%= a.n.scan(/.{2}/).join(" ") %>

+

<%= a.n.scan(/.{2}/).join(' ') %>

Hash (SHA-256):

-

- <%= Base64.decode64(a.public_digest).unpack("H*").join.upcase.scan(/.{2}/).join(" ") %> -

-

Ich bestätige hiermit den obigen öffentlichen Schlüssel für meine elektronische Unterschrift.

+

<%= Base64.decode64(a.public_digest).unpack("H*").join.upcase.scan(/.{2}/).join(" ") %>

+ + + + + + + + + + + +
+ Ort/Datum + + Name/Firma + + <%= t('signature') %> +
+ _________________________ + + _________________________ +




+
+
+
+

<%= t('initialization_letter.x') %>

+ + + + + + + + + +
- _________________________ + <%= t('date') %> - _________________________ + <%= Date.today.strftime('%d.%m.%Y') %>
- _________________________ + <%= t('time') %> + + <%= Time.now.strftime('%H:%M:%S') %>
- Ort/Datum + <%= t('recipient') %> - Name/Firma + <%= bankname %>
- Unterschrift + User-ID + + <%= user_id %> +
+ Partner-ID + + <%= partner_id %>
-
-
-

EBICS-Initialisierungsbrief (HIA) - Seite 1/2

- - - - - - - - - - - - - - - - - - - - - -
- Datum - - <%= Date.today.strftime("%d.%m.%Y") %> -
- Uhrzeit - - <%= Time.now.strftime("%H:%M:%S") %> -
- Empfänger - - <%= bankname %> -
- User-ID - - <%= user_id %> -
- Kunden-ID - - <%= partner_id %> -
-
-

Öffentlicher Authentifikationsschlüssel (X002)

+

<%= t('certificate_type') %> : X002

Exponent (<%= x.key.e.num_bytes * 8 %> Bit):

-

<%= x.e %>

+

<%= x.e %>

Modulus (<%= x.key.n.num_bytes * 8 %> Bit):

-

<%= x.n.scan(/.{2}/).join(" ") %>

+

<%= x.n.scan(/.{2}/).join(' ') %>

Hash (SHA-256):

-

- <%= Base64.decode64(x.public_digest).unpack("H*").join.upcase.scan(/.{2}/).join(" ") %> -

-

Fortsetzung auf Seite 2 ...

-
-

EBICS-Initialisierungsbrief (HIA) - Seite 2/2

+

<%= Base64.decode64(x.public_digest).unpack('H*').join.upcase.scan(/.{2}/).join(' ') %>

+
+
+
+

<%= t('initialization_letter.e') %>

- Datum + <%= t('date') %> - <%= Date.today.strftime("%d.%m.%Y") %> + <%= Date.today.strftime('%d.%m.%Y') %>
- Uhrzeit + <%= t('time') %> - <%= Time.now.strftime("%H:%M:%S") %> + <%= Time.now.strftime('%H:%M:%S') %>
- Empfänger + <%= t('recipient') %> <%= bankname %> @@ -181,51 +186,47 @@
- Kunden-ID + Partner-ID <%= partner_id %>
-
-
-

Öffentlicher Verschlüsselungsschlüssel (E002)

+

<%= t('certificate_type') %> : E002

Exponent (<%= e.key.e.num_bytes * 8 %> Bit):

-

<%= e.e %>

+

<%= e.e %>

Modulus (<%= e.key.n.num_bytes * 8 %> Bit):

-

<%= e.n.scan(/.{2}/).join(" ") %>

+

<%= e.n.scan(/.{2}/).join(' ') %>

+

<%= t('certificate') %>:

Hash (SHA-256):

-

<%= Base64.decode64(e.public_digest).unpack("H*").join.upcase.scan(/.{2}/).join(" ") %>

-

Ich bestätige hiermit die obigen öffentlichen Schlüssel für meinen EBICS-Zugang.

-
-
-
-
+

<%= Base64.decode64(e.public_digest).unpack('H*').join.upcase.scan(/.{2}/).join(' ') %>

- +
- _________________________ + Ort/Datum - _________________________ + Name/Firma - _________________________ + <%= t('signature') %>
- Ort/Datum - - Name/Firma + _________________________ - Unterschrift + _________________________
+
+
+
+
diff --git a/lib/letter/locales/de.yml b/lib/letter/locales/de.yml new file mode 100644 index 0000000..7316e22 --- /dev/null +++ b/lib/letter/locales/de.yml @@ -0,0 +1,12 @@ +de: + epics: + letter: + date: Datum + time: Uhrzeit + recipient: Empfänger + signature: Unterschrift + certificate_type: Art des Zertifikats + initialization_letter: + a: Initialisierungsbrief für SIGNATUR-Zertifikat (INI) + x: Initialisierungsbrief für AUTHENTIFIZIERUNGS-Zertifikat (HIA) + e: Initialisierungsbrief für VERSCHLÜSSELUNGS-Zertifikat (HIA) diff --git a/lib/letter/locales/en.yml b/lib/letter/locales/en.yml new file mode 100644 index 0000000..f681399 --- /dev/null +++ b/lib/letter/locales/en.yml @@ -0,0 +1,12 @@ +en: + epics: + letter: + date: Date + time: Time + recipient: Recipient + signature: Signature + certificate_type: Certificate type + initialization_letter: + a: Initialization letter for SIGNATURE certificate (INI) + x: Initialization letter for AUTHENTICATION certificate (HIA) + e: Initialization letter for ENCRYPTION certificate (HIA) diff --git a/lib/letter/locales/fr.yml b/lib/letter/locales/fr.yml new file mode 100644 index 0000000..dff3fc0 --- /dev/null +++ b/lib/letter/locales/fr.yml @@ -0,0 +1,12 @@ +fr: + epics: + letter: + date: Date + time: Heure + recipient: Destinataire + signature: Signature + certificate_type: Type de certificat + initialization_letter: + a: Lettre d'initialization du certificat de SIGNATURE (INI) + x: Lettre d'initialization du certificat d'AUTHENTIFICATION (HIA) + e: Lettre d'initialization du certificat de CHIFFREMENT (HIA)