forked from Zemistr/l10n-nette-translator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prizpusobeni nette 3.0, pridano db storage, vylepseny funkce panelu.
- Loading branch information
Milan Kocourek
committed
May 2, 2019
1 parent
d980572
commit 90b5612
Showing
11 changed files
with
771 additions
and
469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CREATE TABLE `localization` ( | ||
`id` int(1) unsigned NOT NULL AUTO_INCREMENT, | ||
`text_id` int(1) unsigned NOT NULL, | ||
`lang` char(2) COLLATE utf8mb4_unicode_ci NOT NULL, | ||
`variant` tinyint(1) unsigned NOT NULL DEFAULT '0', | ||
`translation` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, | ||
`ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `text_id_lang_variant` (`text_id`,`lang`,`variant`), | ||
KEY `lang` (`lang`), | ||
CONSTRAINT `x` FOREIGN KEY (`text_id`) REFERENCES `localization_text` (`id`) ON UPDATE CASCADE | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='text translations'; | ||
|
||
CREATE TABLE `localization_text` ( | ||
`id` int(1) unsigned NOT NULL AUTO_INCREMENT, | ||
`ns` varchar(24) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL, | ||
`text` varchar(150) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL, | ||
`ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, | ||
PRIMARY KEY (`id`), | ||
UNIQUE KEY `ns` (`ns`,`text`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='default texts for translations'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,61 @@ | ||
<?php | ||
|
||
namespace l10nNetteTranslator\ApplicationDI; | ||
|
||
use Nette\DI\CompilerExtension; | ||
use Nette\InvalidStateException; | ||
use Nette\PhpGenerator\ClassType; | ||
|
||
class Extension extends CompilerExtension { | ||
public function loadConfiguration() { | ||
$config = $this->getConfig(); | ||
|
||
if (empty($config['languages']) || !is_array($config['languages'])) { | ||
throw new InvalidStateException("Languages must be set, must be array and can't be empty"); | ||
} | ||
|
||
/** @var \Nette\DI\ContainerBuilder $builder */ | ||
$builder = $this->getContainerBuilder(); | ||
|
||
$translator = $builder->addDefinition('l10n_nette_translator.translator'); | ||
$translator->setClass('l10nNetteTranslator\Translator'); | ||
|
||
foreach ($config['languages'] as $language) { | ||
if (empty($language['lang'])) { | ||
throw new InvalidStateException('Key "lang" must be set'); | ||
} | ||
|
||
$lang = $builder->literal("new $language[lang]"); | ||
$plural = isset($language['plural']) ? $builder->literal("new $language[plural]") : $lang; | ||
$default = !empty($language['default']); | ||
|
||
$translator->addSetup('addLanguageAndPlural', [$lang, $plural, $default]); | ||
} | ||
|
||
if (!empty($config['storage'])) { | ||
$translator->addSetup('setStorage', [$config['storage']]); | ||
} | ||
|
||
$panel = $builder->addDefinition('l10n_nette_translator.panel'); | ||
$panel->setClass('l10nNetteTranslator\Panel'); | ||
|
||
$processor = $builder->addDefinition('l10n_nette_translator.processor'); | ||
$processor->setClass('l10nNetteTranslator\TranslatorProcessor'); | ||
} | ||
|
||
public function afterCompile(ClassType $class) { | ||
$initialize = $class->getMethod('initialize'); | ||
$initialize->addBody('$this->getService("tracy.bar")->addPanel($this->getService("l10n_nette_translator.panel"));'); | ||
$initialize->addBody('$response = $this->getService("l10n_nette_translator.processor")->run();'); | ||
$initialize->addBody('if($response instanceof Nette\Application\IResponse) {'); | ||
$initialize->addBody(' $response->send($this->getByType("Nette\Http\IRequest"), $this->getByType("Nette\Http\IResponse"));'); | ||
$initialize->addBody(' exit();'); | ||
$initialize->addBody('}'); | ||
} | ||
class Extension extends CompilerExtension | ||
{ | ||
public function loadConfiguration() | ||
{ | ||
$config = $this->getConfig(); | ||
|
||
if (empty($config['languages']) || !is_array($config['languages'])) { | ||
throw new InvalidStateException("Languages must be set, must be array and can't be empty"); | ||
} | ||
|
||
/** @var \Nette\DI\ContainerBuilder $builder */ | ||
$builder = $this->getContainerBuilder(); | ||
|
||
$translator = $builder->addDefinition('l10n_nette_translator.translator'); | ||
$translator->setClass('l10nNetteTranslator\Translator'); | ||
|
||
foreach ($config['languages'] as $language) { | ||
if (empty($language['lang'])) { | ||
throw new InvalidStateException('Key "lang" must be set'); | ||
} | ||
if (empty($language['namespace'])) { | ||
throw new InvalidStateException('Key "namespace" must be set'); | ||
} | ||
|
||
$lang = $builder->literal("new $language[lang]"); | ||
$plural = isset($language['plural']) ? $builder->literal("new $language[plural]") : $lang; | ||
$default = !empty($language['default']); | ||
|
||
$translator->addSetup('addLanguageAndPlural', [$lang, $plural, $language['namespace'], $default]); | ||
} | ||
|
||
if (!empty($config['storage'])) { | ||
$translator->addSetup('setStorage', [$config['storage']]); | ||
} | ||
|
||
$panel = $builder->addDefinition('l10n_nette_translator.panel'); | ||
$panel->setClass('l10nNetteTranslator\Panel'); | ||
|
||
$processor = $builder->addDefinition('l10n_nette_translator.processor'); | ||
$processor->setClass('l10nNetteTranslator\TranslatorProcessor'); | ||
} | ||
|
||
public function afterCompile(ClassType $class) | ||
{ | ||
$initialize = $class->getMethod('initialize'); | ||
$initialize->addBody('$this->getService("tracy.bar")->addPanel($this->getService("l10n_nette_translator.panel"));'); | ||
$initialize->addBody('$response = $this->getService("l10n_nette_translator.processor")->run();'); | ||
$initialize->addBody('if($response instanceof Nette\Application\IResponse) {'); | ||
$initialize->addBody(' $response->send($this->getByType("Nette\Http\IRequest"), $this->getByType("Nette\Http\IResponse"));'); | ||
$initialize->addBody(' exit();'); | ||
$initialize->addBody('}'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,55 @@ | ||
<?php | ||
|
||
namespace l10nNetteTranslator; | ||
|
||
use l10n\Language\ILanguage; | ||
use l10n\Plural\IPlural; | ||
|
||
class LanguageAndPlural { | ||
/** @var ILanguage */ | ||
private $language; | ||
|
||
/** @var IPlural */ | ||
private $plural; | ||
|
||
/** | ||
* @return ILanguage | ||
*/ | ||
public function getLanguage() { | ||
return $this->language; | ||
} | ||
|
||
/** | ||
* @param ILanguage $language | ||
*/ | ||
public function setLanguage(ILanguage $language) { | ||
$this->language = $language; | ||
} | ||
|
||
/** | ||
* @return IPlural | ||
*/ | ||
public function getPlural() { | ||
return $this->plural; | ||
} | ||
|
||
/** | ||
* @param IPlural $plural | ||
*/ | ||
public function setPlural(IPlural $plural) { | ||
$this->plural = $plural; | ||
} | ||
class LanguageAndPlural | ||
{ | ||
/** @var ILanguage */ | ||
private $language; | ||
|
||
/** @var IPlural */ | ||
private $plural; | ||
|
||
/** | ||
* @return ILanguage | ||
*/ | ||
public function getLanguage() | ||
{ | ||
return $this->language; | ||
} | ||
|
||
/** | ||
* @param ILanguage $language | ||
*/ | ||
public function setLanguage(ILanguage $language) | ||
{ | ||
$this->language = $language; | ||
} | ||
|
||
/** | ||
* @return IPlural | ||
*/ | ||
public function getPlural() | ||
{ | ||
return $this->plural; | ||
} | ||
|
||
/** | ||
* @param IPlural $plural | ||
*/ | ||
public function setPlural(IPlural $plural) | ||
{ | ||
$this->plural = $plural; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString(): string | ||
{ | ||
return $this->language->getIso639_1(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
<?php | ||
|
||
namespace l10nNetteTranslator\Storage; | ||
|
||
use l10nNetteTranslator\Translator; | ||
|
||
interface IStorage extends \l10n\Translator\IStorage { | ||
/** | ||
* @param \l10nNetteTranslator\Translator $translator | ||
* @return void | ||
*/ | ||
public function setTranslator(Translator $translator); | ||
interface IStorage extends \l10n\Translator\IStorage | ||
{ | ||
/** | ||
* @param \l10nNetteTranslator\Translator $translator | ||
* @return void | ||
*/ | ||
public function setTranslator(Translator $translator); | ||
|
||
/** | ||
* @return \l10nNetteTranslator\Translator | ||
*/ | ||
public function getTranslator(); | ||
/** | ||
* @return \l10nNetteTranslator\Translator | ||
*/ | ||
public function getTranslator(); | ||
} |
Oops, something went wrong.