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.
- Loading branch information
0 parents
commit 89136a6
Showing
29 changed files
with
2,620 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## Directory-based project format: | ||
.idea/ | ||
|
||
## File-based project format: | ||
*.ipr | ||
*.iws | ||
|
||
## Plugin-specific files: | ||
|
||
# IntelliJ | ||
out/ | ||
|
||
# mpeltonen/sbt-idea plugin | ||
.idea_modules/ | ||
|
||
composer.lock | ||
vendor/ |
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,81 @@ | ||
checks: | ||
php: | ||
verify_property_names: true | ||
verify_argument_usable_as_reference: true | ||
verify_access_scope_valid: true | ||
variable_existence: true | ||
return_doc_comments: true | ||
parameter_doc_comments: true | ||
fix_use_statements: | ||
remove_unused: true | ||
preserve_multiple: false | ||
preserve_blanklines: false | ||
order_alphabetically: true | ||
use_self_instead_of_fqcn: true | ||
uppercase_constants: true | ||
simplify_boolean_return: true | ||
remove_extra_empty_lines: true | ||
phpunit_assertions: true | ||
optional_parameters_at_the_end: true | ||
newline_at_end_of_file: true | ||
function_in_camel_caps: false | ||
fix_line_ending: true | ||
encourage_single_quotes: true | ||
classes_in_camel_caps: true | ||
avoid_multiple_statements_on_same_line: true | ||
avoid_fixme_comments: true | ||
return_doc_comment_if_not_inferrable: true | ||
param_doc_comment_if_not_inferrable: true | ||
|
||
coding_style: | ||
php: | ||
indentation: | ||
general: | ||
use_tabs: true | ||
spaces: | ||
before_parentheses: | ||
closure_definition: true | ||
around_operators: | ||
concatenation: false | ||
other: | ||
after_type_cast: false | ||
braces: | ||
classes_functions: | ||
class: end-of-line | ||
function: end-of-line | ||
closure: end-of-line | ||
if: | ||
opening: end-of-line | ||
else_on_new_line: true | ||
for: | ||
opening: end-of-line | ||
while: | ||
opening: end-of-line | ||
do_while: | ||
opening: end-of-line | ||
while_on_new_line: true | ||
switch: | ||
opening: end-of-line | ||
try: | ||
opening: end-of-line | ||
catch_on_new_line: true | ||
finally_on_new_line: true | ||
upper_lower_casing: | ||
keywords: | ||
general: lower | ||
constants: | ||
true_false_null: lower | ||
|
||
filter: | ||
excluded_paths: | ||
- tests/* | ||
|
||
|
||
build: | ||
tests: | ||
override: | ||
- | ||
command: phpunit --configuration phpunit.xml --coverage-clover=some-file | ||
coverage: | ||
file: some-file | ||
format: php-clover |
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,13 @@ | ||
language: php | ||
php: | ||
- 5.4 | ||
- 5.5 | ||
- 5.6 | ||
- hhvm | ||
- nightly | ||
|
||
before_script: | ||
- composer self-update | ||
- composer install --prefer-source --no-interaction --dev | ||
|
||
script: phpunit --configuration phpunit.xml --coverage-text |
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 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Martin Zeman | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,71 @@ | ||
[![Build Status](https://travis-ci.org/Zemistr/l10nNetteTranslator.svg?branch=master)](https://travis-ci.org/Zemistr/l10nNetteTranslator) | ||
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Zemistr/l10nNetteTranslator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Zemistr/l10nNetteTranslator/?branch=master) | ||
[![Scrutinizer Code Coverage](https://scrutinizer-ci.com/g/Zemistr/l10nNetteTranslator/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Zemistr/l10nNetteTranslator/?branch=master) | ||
[![Packagist Total Downloads](https://img.shields.io/packagist/dt/zemistr/l10nNetteTranslator.svg)](https://packagist.org/packages/zemistr/l10nNetteTranslator) | ||
[![License](https://img.shields.io/packagist/l/zemistr/l10nNetteTranslator.svg)](http://opensource.org/licenses/mit-license.php) | ||
|
||
# l10nNetteTranslator | ||
l10n translator for [Nette](http://nette.org/) with simple panel for [Tracy](http://tracy.nette.org/en/) | ||
|
||
## Packagist | ||
l10nNetteTranslator is available on [Packagist.org](https://packagist.org/packages/zemistr/l10nNetteTranslator), | ||
just add the dependency to your composer.json. | ||
|
||
```javascript | ||
{ | ||
"require" : { | ||
"zemistr/l10nNetteTranslator": "1.*" | ||
} | ||
} | ||
``` | ||
|
||
or run Composer command: | ||
```php | ||
php composer.phar require zemistr/l10nNetteTranslator | ||
``` | ||
|
||
## Usage without composer | ||
|
||
```php | ||
<?php | ||
require('src/l10nNetteTranslator.php'); | ||
``` | ||
|
||
## Example usage (standard usage with file storage) | ||
Just add following lines into your config: | ||
|
||
```yaml | ||
extensions: | ||
translator: l10nNetteTranslator\ApplicationDI\Extension | ||
|
||
translator: | ||
# languages are required | ||
languages: | ||
- | ||
lang: l10n\Language\CzechLanguage # must implements l10n\Language\ILanguage | ||
plural: l10n\Plural\PluralRule8 # must implements l10n\Plural\IPlural | ||
|
||
- | ||
lang: l10n\Language\SlovakLanguage # if language implements l10n\Plural\IPlural, you can ignore plural section | ||
|
||
- | ||
lang: l10n\Language\EnglishLanguage | ||
default: true # if is not set, the first language will be set as default | ||
|
||
# storage is optional | ||
storage: @translator_storage_adapter # must implements l10nNetteTranslator\Storage\IStorage | ||
|
||
services: | ||
# You can use any storage implements Nette\Caching\IStorage | ||
translator_nette_storage: | ||
class: Nette\Caching\Storages\FileStorage(%appDir%/Texts) # Texts will be saved in %appDir%/Texts as file named by ISO 639-1 | ||
autowired: false | ||
|
||
translator_simple_nette_storage: l10nNetteTranslator\Storage\SimpleNetteStorage(@translator_storage) | ||
|
||
``` | ||
|
||
|
||
----- | ||
|
||
(c) Martin Zeman (Zemistr), 2015 (http://zemistr.eu) |
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,35 @@ | ||
{ | ||
"name": "zemistr/l10nnettetranslator", | ||
"description": "Simple l10n translator panel for Tracy", | ||
"keywords": [ | ||
"l10n", | ||
"localization", | ||
"translator", | ||
"nette", | ||
"tracy" | ||
], | ||
"homepage": "https://github.com/zemistr/l10nnettetranslator", | ||
"minimum-stability": "stable", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Martin Zeman (Zemistr)", | ||
"homepage": "http://zemistr.eu" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0", | ||
"zemistr/l10n": "1.*", | ||
"nette/di": "2.3.*", | ||
"nette/php-generator": "2.3.*", | ||
"nette/application": "2.3.*", | ||
"nette/http": "2.3.*", | ||
"nette/utils": "2.3.*", | ||
"tracy/tracy": "2.3.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"l10nNetteTranslator\\": "src/l10nNetteTranslator" | ||
} | ||
} | ||
} |
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,27 @@ | ||
extensions: | ||
translator: l10nNetteTranslator\ApplicationDI\Extension | ||
|
||
translator: | ||
# languages are required | ||
languages: | ||
- | ||
lang: l10n\Language\CzechLanguage # must implements l10n\Language\ILanguage | ||
plural: l10n\Plural\PluralRule8 # must implements l10n\Plural\IPlural | ||
|
||
- | ||
lang: l10n\Language\SlovakLanguage # if language implements l10n\Plural\IPlural, you can ignore plural section | ||
|
||
- | ||
lang: l10n\Language\EnglishLanguage | ||
default: true # if is not set, the first language will be set as default | ||
|
||
# storage is optional | ||
storage: @translator_storage_adapter # must implements l10nNetteTranslator\Storage\IStorage | ||
|
||
services: | ||
# You can use any storage implements Nette\Caching\IStorage | ||
translator_nette_storage: | ||
class: Nette\Caching\Storages\FileStorage(%appDir%/Texts) # Texts will be saved in %appDir%/Texts as file named by ISO 639-1 | ||
autowired: false | ||
|
||
translator_simple_nette_storage: l10nNetteTranslator\Storage\SimpleNetteStorage(@translator_storage) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<phpunit bootstrap="tests/bootstrap.php" colors="true"> | ||
<testsuites> | ||
<testsuite name="All tests"> | ||
<directory>./tests/</directory> | ||
<exclude>./src/l10nNetteTranslator/Templates</exclude> | ||
<exclude>./data</exclude> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
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,18 @@ | ||
<?php | ||
spl_autoload_register( | ||
function ($class_name) { | ||
static $class_map = [ | ||
'l10nNetteTranslator\\ApplicationDI\\Extension' => 'ApplicationDI/Extension.php', | ||
'l10nNetteTranslator\\LanguageAndPlural' => 'LanguageAndPlural.php', | ||
'l10nNetteTranslator\\Panel' => 'Panel.php', | ||
'l10nNetteTranslator\\Storage\\IStorage' => 'Storage/IStorage.php', | ||
'l10nNetteTranslator\\Storage\\SimpleNetteStorage' => 'Storage/SimpleNetteStorage.php', | ||
'l10nNetteTranslator\\Translator' => 'Translator.php', | ||
'l10nNetteTranslator\\TranslatorProcessor' => 'TranslatorProcessor.php', | ||
]; | ||
|
||
if (isset($class_map[$class_name])) { | ||
require __DIR__ . '/l10nNetteTranslator/' . $class_map[$class_name]; | ||
} | ||
} | ||
); |
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,54 @@ | ||
<?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('}'); | ||
} | ||
} |
Oops, something went wrong.