Skip to content

Commit

Permalink
add Czech translations
Browse files Browse the repository at this point in the history
  • Loading branch information
KuceraMartin committed Jul 4, 2017
1 parent b281464 commit 2d58d88
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 15 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
}
},
"autoload": {
"psr-4": { "Nextras\\Datagrid\\": "src" }
"psr-4": { "Nextras\\Datagrid\\": "src" },
"classmap": [
"src/exceptions.php"
]
}
}
2 changes: 1 addition & 1 deletion src/Datagrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
61 changes: 48 additions & 13 deletions src/DefaultTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
15 changes: 15 additions & 0 deletions src/exceptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* This file is part of the Nextras community extensions of Nette Framework
*
* @license MIT
* @link https://github.com/nextras
*/

namespace Nextras\Datagrid;


class InvalidArgumentException extends \InvalidArgumentException
{
}

0 comments on commit 2d58d88

Please sign in to comment.