1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace byrokrat\paperinvoice\I18n; |
4
|
|
|
|
5
|
|
|
use byrokrat\paperinvoice\I18nInterface; |
6
|
|
|
use byrokrat\amount\Amount; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Swedish internationalization |
10
|
|
|
* |
11
|
|
|
* @author Hannes Forsgård <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class Swedish implements I18nInterface |
14
|
|
|
{ |
15
|
|
|
public static $translations = array( |
16
|
|
|
'INVOICE' => 'FAKTURA', |
17
|
|
|
'Page ' => 'Sida ', |
18
|
|
|
' of ' => ' av ', |
19
|
|
|
'Invoice date' => 'Fakturadatum', |
20
|
|
|
'Invoice number' => 'Fakturanummer', |
21
|
|
|
'Reference' => 'OCR-nummer', |
22
|
|
|
'Payment term' => 'Betalningsvillkor', |
23
|
|
|
' days' => ' dagar', |
24
|
|
|
'Expiry date' => 'Förfallodag', |
25
|
|
|
'VAT rate' => 'Momssats', |
26
|
|
|
'Amount' => 'Antal', |
27
|
|
|
'Unit cost' => 'Á pris', |
28
|
|
|
'Total' => 'Summa', |
29
|
|
|
'Basis' => 'Underlag', |
30
|
|
|
'Total ex. VAT' => 'Summa ex. moms', |
31
|
|
|
'Total VAT' => 'Total moms', |
32
|
|
|
'Deduction' => 'Erlagd förskottsbetalning', |
33
|
|
|
'Tax registered' => 'Godkänd för F-skatt.', |
34
|
|
|
'To pay' => 'Att betala', |
35
|
|
|
'Address' => 'Svarsadress', |
36
|
|
|
'Identification' => 'Organisationsnr', |
37
|
|
|
'VAT number' => 'Momsreg.nr.', |
38
|
|
|
'Phone' => 'Telefon', |
39
|
|
|
'E-mail' => 'E-post', |
40
|
|
|
'Continues on next page..' => 'Sammanställningen fortsätter på nästa sida..' |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
private $currencyFormatter; |
44
|
|
|
|
45
|
|
View Code Duplication |
public function __construct(\NumberFormatter $currencyFormatter = null) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
if (!$currencyFormatter) { |
48
|
|
|
$currencyFormatter = new \NumberFormatter('sv', \NumberFormatter::CURRENCY); |
49
|
|
|
$currencyFormatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, ''); |
50
|
|
|
$currencyFormatter->setSymbol(\NumberFormatter::INTL_CURRENCY_SYMBOL, ''); |
51
|
|
|
$currencyFormatter->setTextAttribute(\NumberFormatter::NEGATIVE_PREFIX, "-"); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$this->currencyFormatter = $currencyFormatter; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function translate($string) |
58
|
|
|
{ |
59
|
|
|
if (array_key_exists($string, self::$translations)) { |
60
|
|
|
return self::$translations[$string]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
return $string; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function formateDate(\DateTimeInterface $datetime) |
67
|
|
|
{ |
68
|
|
|
return $datetime->format('Y-m-d'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function formatCurrency(Amount $amount) |
72
|
|
|
{ |
73
|
|
|
return $this->currencyFormatter->format($amount->getFloat()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function formatCurrencySymbol(Amount $amount, $currency) |
77
|
|
|
{ |
78
|
|
|
return $this->currencyFormatter->formatCurrency($amount->getFloat(), $currency); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function formatPercentage($amount) |
82
|
|
|
{ |
83
|
|
|
return $amount; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function formatUnits($units) |
87
|
|
|
{ |
88
|
|
|
return $units; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.