Skip to content

Commit 2d58d88

Browse files
committed
add Czech translations
1 parent b281464 commit 2d58d88

File tree

4 files changed

+68
-15
lines changed

4 files changed

+68
-15
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
}
2525
},
2626
"autoload": {
27-
"psr-4": { "Nextras\\Datagrid\\": "src" }
27+
"psr-4": { "Nextras\\Datagrid\\": "src" },
28+
"classmap": [
29+
"src/exceptions.php"
30+
]
2831
}
2932
}

src/Datagrid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class Datagrid extends UI\Control
9696
public function __construct()
9797
{
9898
parent::__construct();
99-
$this->translator = new DefaultTranslator();
99+
$this->translator = new DefaultTranslator(DefaultTranslator::LANG_EN);
100100
}
101101

102102

src/DefaultTranslator.php

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,63 @@ class DefaultTranslator implements ITranslator
1818
use SmartObject;
1919

2020

21+
const LANG_EN = 'en';
22+
const LANG_CS = 'cs';
23+
2124
const TRANSLATIONS = [
22-
'nextras.datagrid.filter.submit' => 'Filter',
23-
'nextras.datagrid.filter.cancel' => 'Cancel',
25+
self::LANG_EN => [
26+
'nextras.datagrid.filter.submit' => 'Filter',
27+
'nextras.datagrid.filter.cancel' => 'Cancel',
28+
29+
'nextras.datagrid.edit.label' => 'Edit',
30+
'nextras.datagrid.edit.save' => 'Save',
31+
'nextras.datagrid.edit.cancel' => 'Cancel',
32+
33+
'nextras.datagrid.action.label' => 'Action',
34+
'nextras.datagrid.action.prompt' => '- select action -',
35+
'nextras.datagrid.action.process' => 'Do',
2436

25-
'nextras.datagrid.edit.label' => 'Edit',
26-
'nextras.datagrid.edit.save' => 'Save',
27-
'nextras.datagrid.edit.cancel' => 'Cancel',
37+
'nextras.datagrid.pagination.first' => 'First',
38+
'nextras.datagrid.pagination.previous' => 'Previous',
39+
'nextras.datagrid.pagination.next' => 'Next',
40+
'nextras.datagrid.pagination.last' => 'Last',
41+
],
42+
self::LANG_CS => [
43+
'nextras.datagrid.filter.submit' => 'Filtrovat',
44+
'nextras.datagrid.filter.cancel' => 'Zrušit',
2845

29-
'nextras.datagrid.action.label' => 'Action',
30-
'nextras.datagrid.action.prompt' => '- select action -',
31-
'nextras.datagrid.action.process' => 'Do',
46+
'nextras.datagrid.edit.label' => 'Upravit',
47+
'nextras.datagrid.edit.save' => 'Uložit',
48+
'nextras.datagrid.edit.cancel' => 'Zrušit',
3249

33-
'nextras.datagrid.pagination.first' => 'First',
34-
'nextras.datagrid.pagination.previous' => 'Previous',
35-
'nextras.datagrid.pagination.next' => 'Next',
36-
'nextras.datagrid.pagination.last' => 'Last',
50+
'nextras.datagrid.action.label' => 'Akce',
51+
'nextras.datagrid.action.prompt' => '- zvolte akci -',
52+
'nextras.datagrid.action.process' => 'OK',
53+
54+
'nextras.datagrid.pagination.first' => 'První',
55+
'nextras.datagrid.pagination.previous' => 'Poslední',
56+
'nextras.datagrid.pagination.next' => 'Další',
57+
'nextras.datagrid.pagination.last' => 'Předchozí',
58+
],
3759
];
3860

3961

62+
/** @var string */
63+
private $language;
64+
65+
66+
public function __construct($language)
67+
{
68+
if (!isset(self::TRANSLATIONS[$language])) {
69+
throw new InvalidArgumentException("Unsupported language '$language'");
70+
}
71+
$this->language = $language;
72+
}
73+
74+
4075
public function translate($message, $count = NULL)
4176
{
42-
return isset(self::TRANSLATIONS[$message]) ? self::TRANSLATIONS[$message] : $message;
77+
return isset(self::TRANSLATIONS[$this->language][$message]) ? self::TRANSLATIONS[$this->language][$message] : $message;
4378
}
4479

4580
}

src/exceptions.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Nextras community extensions of Nette Framework
5+
*
6+
* @license MIT
7+
* @link https://github.com/nextras
8+
*/
9+
10+
namespace Nextras\Datagrid;
11+
12+
13+
class InvalidArgumentException extends \InvalidArgumentException
14+
{
15+
}

0 commit comments

Comments
 (0)