Skip to content

Commit

Permalink
Translates letter
Browse files Browse the repository at this point in the history
  • Loading branch information
jplot committed Aug 29, 2024
1 parent 651c357 commit ad09384
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 174 deletions.
1 change: 1 addition & 0 deletions epics.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions lib/epics.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'openssl'
require 'base64'
require 'erb'
require 'i18n'
require 'json'
require 'zlib'
require 'zip'
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions lib/epics/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions lib/epics/letter_renderer.rb
Original file line number Diff line number Diff line change
@@ -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, **options)
I18n.translate(key, **{ locale: @client.locale, scope: I18N_SCOPE }.merge(options))
end

alias_method :t, :translate

def_delegators :@client, :host_id, :user_id, :partner_id, :a, :x, :e

def render(bankname)
ERB.new(File.read(TEMPLATE_PATH)).result(binding)
end
end
Loading

0 comments on commit ad09384

Please sign in to comment.