Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fchris82 committed May 10, 2017
2 parents cde8041 + 1832626 commit 80d236f
Show file tree
Hide file tree
Showing 27 changed files with 655 additions and 64 deletions.
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

env:
Expand All @@ -32,8 +33,17 @@ matrix:
env: SYMFONY_VERSION=2.3.*
- php: 5.6
env: SYMFONY_VERSION=2.7.*
- php: 7.0
env: SYMFONY_VERSION=2.7.*
- php: 7.1
env: SYMFONY_VERSION=2.8.*
- php: 5.6
env: SYMFONY_VERSION=3.0.*
env: SYMFONY_VERSION=^3.0
- php: 7.0
env: SYMFONY_VERSION=^3.0
- php: 7.1
env: SYMFONY_VERSION=^3.0


before_install:
- travis_retry composer self-update
Expand Down
32 changes: 32 additions & 0 deletions Annotation/TransArrayKeys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* Copyright 2011 Johannes M. Schmitt <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace JMS\TranslationBundle\Annotation;

/**
* @Annotation
*
* @author Krisztián Ferenczi <[email protected]>
*/
final class TransArrayKeys
{
/**
* @var string
*/
public $domain = 'messages';
}
32 changes: 32 additions & 0 deletions Annotation/TransArrayValues.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* Copyright 2011 Johannes M. Schmitt <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace JMS\TranslationBundle\Annotation;

/**
* @Annotation
*
* @author Krisztián Ferenczi <[email protected]>
*/
final class TransArrayValues
{
/**
* @var string
*/
public $domain = 'messages';
}
32 changes: 32 additions & 0 deletions Annotation/TransString.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* Copyright 2011 Johannes M. Schmitt <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace JMS\TranslationBundle\Annotation;

/**
* @Annotation
*
* @author Krisztián Ferenczi <[email protected]>
*/
final class TransString
{
/**
* @var string
*/
public $domain = 'messages';
}
8 changes: 7 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Changelog

### 1.3.1 to UNRELEASED
### 1.3.2 to UNRELEASED

### 1.3.1 to 1.3.2
* Added configuration options to disable date/sources in xliff dump
* Fixed trim bug with @XBundle notation
* Added support for php 7.1
* Added Twig 2 support

### 1.3.0 to 1.3.1

Expand Down
9 changes: 8 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public function getConfigTreeBuilder()
->arrayNode('locales')
->prototype('scalar')->end()
->end()
->arrayNode('dumper')
->addDefaultsIfNotSet()
->children()
->booleanNode('add_date')->defaultTrue()->end()
->booleanNode('add_references')->defaultTrue()->end()
->end()
->end()
->scalarNode('source_language')->defaultValue('en')->end()
->arrayNode('custom_form_config_names')
->prototype('scalar')->end()
Expand Down Expand Up @@ -72,7 +79,7 @@ public function getConfigTreeBuilder()
if (false === $pos = strpos($v, '/')) {
$bundleName = substr($v, 1);
} else {
$bundleName = substr($v, 1, $pos - 2);
$bundleName = substr($v, 1, $pos - 1);
}

$bundles = $c->getParameter('kernel.bundles');
Expand Down
5 changes: 5 additions & 0 deletions DependencyInjection/JMSTranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('jms_translation.source_language', $config['source_language']);
$container->setParameter('jms_translation.locales', $config['locales']);


// Extend form extractor
$def = $container->getDefinition('jms_translation.extractor.file.form_extractor');
$def->addMethodCall('addCustomTranslationFields', [$config['custom_form_config_names']]);

foreach ($config['dumper'] as $option => $value) {
$container->setParameter("jms_translation.dumper.{$option}", $value);
}

$requests = array();
foreach ($config['configs'] as $name => $extractConfig) {
$def = new Definition('JMS\TranslationBundle\Translation\ConfigBuilder');
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ $this->trans('user.create.success.%email%', ['%email%' => $user->getEmail()]);

> The double `""` sign is the escaped `"` in the `AltTrans` annotation value.
- Add new Trans* Annotations: `TransArrayKeys`, `TransArrayValues`, `TransString` . You can handle the strings in var:

```php
<?php

/** @TransArrayValues("error") */
$msgs = [
/** @AltTrans("Error 1", locale="en") */
'error.msg1',
/** @AltTrans("Error 2", locale="en") */
'error.msg2',
/** @AltTrans("Error 3", locale="en") */
'error.msg3',
];
/** @Ignore */
$this->trans($msgs[$errorId], [], "error");
```

JMSTranslationBundle [![Build Status](https://secure.travis-ci.org/schmittjoh/JMSTranslationBundle.png?branch=master)](http://travis-ci.org/schmittjoh/JMSTranslationBundle) [![Join the chat at https://gitter.im/schmittjoh/JMSTranslationBundle](https://badges.gitter.im/schmittjoh/JMSTranslationBundle.svg)](https://gitter.im/schmittjoh/JMSTranslationBundle?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
====================

Expand Down
25 changes: 23 additions & 2 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<parameter key="jms_translation.extractor_manager.class">JMS\TranslationBundle\Translation\ExtractorManager</parameter>
<parameter key="jms_translation.extractor.file_extractor.class">JMS\TranslationBundle\Translation\Extractor\FileExtractor</parameter>
<parameter key="jms_translation.extractor.file.annotation_extractor">JMS\TranslationBundle\Translation\Extractor\File\AnnotationExtractor</parameter>
<parameter key="jms_translation.extractor.file.default_php_extractor">JMS\TranslationBundle\Translation\Extractor\File\DefaultPhpFileExtractor</parameter>
<parameter key="jms_translation.extractor.file.translation_container_extractor">JMS\TranslationBundle\Translation\Extractor\File\TranslationContainerExtractor</parameter>
<parameter key="jms_translation.extractor.file.twig_extractor">JMS\TranslationBundle\Translation\Extractor\File\TwigFileExtractor</parameter>
Expand Down Expand Up @@ -64,12 +65,24 @@
<call method="setSourceLanguage">
<argument>%jms_translation.source_language%</argument>
</call>
<call method="setAddDate">
<argument>%jms_translation.dumper.add_date%</argument>
</call>
<call method="setAddReference">
<argument>%jms_translation.dumper.add_references%</argument>
</call>
<tag name="jms_translation.dumper" format="xliff" />
</service>
<service id="jms_translation.dumper.xlf_dumper" class="%jms_translation.dumper.xliff_dumper.class%" public="false">
<call method="setSourceLanguage">
<argument>%jms_translation.source_language%</argument>
</call>
<call method="setAddDate">
<argument>%jms_translation.dumper.add_date%</argument>
</call>
<call method="setAddReference">
<argument>%jms_translation.dumper.add_references%</argument>
</call>
<tag name="jms_translation.dumper" format="xlf" />
</service>
<service id="jms_translation.dumper.yaml_dumper" class="%jms_translation.dumper.yaml_dumper.class%" public="false">
Expand All @@ -88,6 +101,11 @@
<argument type="service" id="twig" />
<argument type="service" id="logger" />
</service>
<service id="jms_translation.extractor.file.annotation_extractor" class="%jms_translation.extractor.file.annotation_extractor%" public="false">
<argument type="service" id="jms_translation.doc_parser" />
<argument type="service" id="jms_translation.file_source_factory" />
<tag name="jms_translation.file_visitor" />
</service>
<service id="jms_translation.extractor.file.default_php_extractor" class="%jms_translation.extractor.file.default_php_extractor%" public="false">
<argument type="service" id="jms_translation.doc_parser" />
<argument type="service" id="jms_translation.file_source_factory" />
Expand Down Expand Up @@ -120,10 +138,13 @@
<service id="jms_translation.doc_parser" class="Doctrine\Common\Annotations\DocParser" public="false">
<call method="setImports">
<argument type="collection">
<argument key="alttrans">JMS\TranslationBundle\Annotation\AltTrans</argument>
<argument key="desc">JMS\TranslationBundle\Annotation\Desc</argument>
<argument key="meaning">JMS\TranslationBundle\Annotation\Meaning</argument>
<argument key="ignore">JMS\TranslationBundle\Annotation\Ignore</argument>
<argument key="alttrans">JMS\TranslationBundle\Annotation\AltTrans</argument>
<argument key="meaning">JMS\TranslationBundle\Annotation\Meaning</argument>
<argument key="transarraykeys">JMS\TranslationBundle\Annotation\TransArrayKeys</argument>
<argument key="transarrayvalues">JMS\TranslationBundle\Annotation\TransArrayValues</argument>
<argument key="transstring">JMS\TranslationBundle\Annotation\TransString</argument>
</argument>
</call>
<call method="setIgnoreNotImportedAnnotations">
Expand Down
4 changes: 2 additions & 2 deletions Resources/views/Translate/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ parent() }}
<script language="javascript" type="text/javascript">
var updateMessagePath = {{ path("jms_translation_update_message", {"config": selectedConfig, "domain": selectedDomain, "locale": selectedLocale})|json_encode|raw }};
var isWritable = {{ isWriteable is sameas(true) ? 'true' : 'false' }};
var isWritable = {{ isWriteable is same as(true) ? 'true' : 'false' }};
var JMS = new JMSTranslationManager(updateMessagePath, isWritable);
JMS.ready();
Expand Down Expand Up @@ -33,7 +33,7 @@
</select>
</form>

{% if isWriteable is sameas(false) %}
{% if isWriteable is same as(false) %}
<div class="alert-message error">
The translation file "<strong>{{ file }}</strong>" is not writable.
</div>
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Translate/messages.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<p><abbr title="{{ id }}">{{ id|slice(0, 25) }}{% if id|length > 25 %}...{% endif %}</abbr></p>
</td>
<td>
<textarea data-id="{{ id }}" class="span6"{% if isWriteable is sameas(false) %} readonly="readonly"{% endif %}>{{ message.localeString }}</textarea></td>
<textarea data-id="{{ id }}" class="span6"{% if isWriteable is same as(false) %} readonly="readonly"{% endif %}>{{ message.localeString }}</textarea></td>
<td>
{% if message.meaning is not empty %}
<h6>Meaning</h6>
Expand Down
75 changes: 75 additions & 0 deletions Tests/Translation/Extractor/File/AnnotationExtractorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/*
* Copyright 2011 Johannes M. Schmitt <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace JMS\TranslationBundle\Tests\Translation\Extractor\File;

use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\Extractor\File\AnnotationExtractor;
use JMS\TranslationBundle\Translation\Extractor\File\DefaultPhpFileExtractor;

class AnnotationExtractorTest extends BasePhpFileExtractorTest
{
public function testExtractController()
{
$catalogue = $this->extract('Controller.php');

$fileSourceFactory = $this->getFileSourceFactory();
$fixtureSplInfo = new \SplFileInfo(__DIR__.'/Fixture/Controller.php');

$expected = new MessageCatalogue();

$message = new Message('simple.text1');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 94));
$expected->add($message);

$message = new Message('simple.text2');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 95));
$message->addAlternativeTranslation('en', 'Simple text 2');
$expected->add($message);

$message = new Message('subarray.value1', 'subarray');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 100));
$message->addAlternativeTranslation('en', 'Sub array value1');
$expected->add($message);

$message = new Message('subarray.value2', 'subarray');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 102));
$message->addAlternativeTranslation('en', 'Sub array value2');
$expected->add($message);

$message = new Message('user.role.partner');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 108));
$expected->add($message);

$message = new Message('user.role.supporter');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 109));
$expected->add($message);

$message = new Message('user.role.admin');
$message->addSource($fileSourceFactory->create($fixtureSplInfo, 110));
$expected->add($message);

$this->assertEquals($expected, $catalogue);
}

protected function getDefaultExtractor()
{
return new AnnotationExtractor($this->getDocParser(), $this->getFileSourceFactory());
}
}
3 changes: 3 additions & 0 deletions Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ final protected function getDocParser()
'meaning' => 'JMS\TranslationBundle\Annotation\Meaning',
'ignore' => 'JMS\TranslationBundle\Annotation\Ignore',
'alttrans' => 'JMS\TranslationBundle\Annotation\AltTrans',
'transarraykeys' => 'JMS\TranslationBundle\Annotation\TransArrayKeys',
'transarrayvalues' => 'JMS\TranslationBundle\Annotation\TransArrayValues',
'transstring' => 'JMS\TranslationBundle\Annotation\TransString',
));
$docParser->setIgnoreNotImportedAnnotations(true);

Expand Down
Loading

0 comments on commit 80d236f

Please sign in to comment.