From 2d58d880019823c222dcc644a805971100d163ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ku=C4=8Dera?= Date: Tue, 4 Jul 2017 11:21:56 +0200 Subject: [PATCH] add Czech translations --- composer.json | 5 +++- src/Datagrid.php | 2 +- src/DefaultTranslator.php | 61 ++++++++++++++++++++++++++++++--------- src/exceptions.php | 15 ++++++++++ 4 files changed, 68 insertions(+), 15 deletions(-) create mode 100644 src/exceptions.php diff --git a/composer.json b/composer.json index ca5678d..b50ea47 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,9 @@ } }, "autoload": { - "psr-4": { "Nextras\\Datagrid\\": "src" } + "psr-4": { "Nextras\\Datagrid\\": "src" }, + "classmap": [ + "src/exceptions.php" + ] } } diff --git a/src/Datagrid.php b/src/Datagrid.php index b2d9a92..3fd3586 100644 --- a/src/Datagrid.php +++ b/src/Datagrid.php @@ -96,7 +96,7 @@ class Datagrid extends UI\Control public function __construct() { parent::__construct(); - $this->translator = new DefaultTranslator(); + $this->translator = new DefaultTranslator(DefaultTranslator::LANG_EN); } diff --git a/src/DefaultTranslator.php b/src/DefaultTranslator.php index 4a32da3..590b903 100644 --- a/src/DefaultTranslator.php +++ b/src/DefaultTranslator.php @@ -18,28 +18,63 @@ class DefaultTranslator implements ITranslator use SmartObject; + const LANG_EN = 'en'; + const LANG_CS = 'cs'; + const TRANSLATIONS = [ - 'nextras.datagrid.filter.submit' => 'Filter', - 'nextras.datagrid.filter.cancel' => 'Cancel', + self::LANG_EN => [ + 'nextras.datagrid.filter.submit' => 'Filter', + 'nextras.datagrid.filter.cancel' => 'Cancel', + + 'nextras.datagrid.edit.label' => 'Edit', + 'nextras.datagrid.edit.save' => 'Save', + 'nextras.datagrid.edit.cancel' => 'Cancel', + + 'nextras.datagrid.action.label' => 'Action', + 'nextras.datagrid.action.prompt' => '- select action -', + 'nextras.datagrid.action.process' => 'Do', - 'nextras.datagrid.edit.label' => 'Edit', - 'nextras.datagrid.edit.save' => 'Save', - 'nextras.datagrid.edit.cancel' => 'Cancel', + 'nextras.datagrid.pagination.first' => 'First', + 'nextras.datagrid.pagination.previous' => 'Previous', + 'nextras.datagrid.pagination.next' => 'Next', + 'nextras.datagrid.pagination.last' => 'Last', + ], + self::LANG_CS => [ + 'nextras.datagrid.filter.submit' => 'Filtrovat', + 'nextras.datagrid.filter.cancel' => 'Zrušit', - 'nextras.datagrid.action.label' => 'Action', - 'nextras.datagrid.action.prompt' => '- select action -', - 'nextras.datagrid.action.process' => 'Do', + 'nextras.datagrid.edit.label' => 'Upravit', + 'nextras.datagrid.edit.save' => 'Uložit', + 'nextras.datagrid.edit.cancel' => 'Zrušit', - 'nextras.datagrid.pagination.first' => 'First', - 'nextras.datagrid.pagination.previous' => 'Previous', - 'nextras.datagrid.pagination.next' => 'Next', - 'nextras.datagrid.pagination.last' => 'Last', + 'nextras.datagrid.action.label' => 'Akce', + 'nextras.datagrid.action.prompt' => '- zvolte akci -', + 'nextras.datagrid.action.process' => 'OK', + + 'nextras.datagrid.pagination.first' => 'První', + 'nextras.datagrid.pagination.previous' => 'Poslední', + 'nextras.datagrid.pagination.next' => 'Další', + 'nextras.datagrid.pagination.last' => 'Předchozí', + ], ]; + /** @var string */ + private $language; + + + public function __construct($language) + { + if (!isset(self::TRANSLATIONS[$language])) { + throw new InvalidArgumentException("Unsupported language '$language'"); + } + $this->language = $language; + } + + public function translate($message, $count = NULL) { - return isset(self::TRANSLATIONS[$message]) ? self::TRANSLATIONS[$message] : $message; + return isset(self::TRANSLATIONS[$this->language][$message]) ? self::TRANSLATIONS[$this->language][$message] : $message; } } diff --git a/src/exceptions.php b/src/exceptions.php new file mode 100644 index 0000000..d33178c --- /dev/null +++ b/src/exceptions.php @@ -0,0 +1,15 @@ +