Skip to content

Commit

Permalink
Support storage 1.0.1 (#5)
Browse files Browse the repository at this point in the history
* Update composer.json

* Update dependencies

* Fixes

* Updated travis file

* CS fixes

* Use 1.0

* Bugfix

* Bump version

* Always disable backup
  • Loading branch information
Nyholm committed Jul 11, 2018
1 parent 8e61915 commit 34d7334
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 34 deletions.
58 changes: 44 additions & 14 deletions .travis.yml
Expand Up @@ -9,29 +9,59 @@ branches:
- /^analysis-.*$/
- /^patch-.*$/

php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2

env:
global:
- TEST_COMMAND="composer test"
- SYMFONY_PHPUNIT_VERSION="6.3"

matrix:
fast_finish: true
include:
- php: 5.5
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci"
- php: hhvm
dist: trusty
fast_finish: true
include:
# Test with lowest dependencies
- php: 7.1
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak"
- php: 5.5
env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" SYMFONY_DEPRECATIONS_HELPER="weak" SYMFONY_PHPUNIT_VERSION="5.7"

# Test the latest stable release
- php: 5.5
env: SYMFONY_PHPUNIT_VERSION="5.7"
- php: 5.6
env: SYMFONY_PHPUNIT_VERSION="5.7"
- php: 7.0
- php: 7.1
- php: 7.2
env: COVERAGE=true TEST_COMMAND="composer test-ci"

# Force some major versions of Symfony
- php: 7.2
env: DEPENDENCIES="dunglas/symfony-lock:^2"
- php: 7.2
env: DEPENDENCIES="dunglas/symfony-lock:^3"
- php: 7.2
env: DEPENDENCIES="dunglas/symfony-lock:^4"

# Latest commit to master
- php: 7.2
env: STABILITY="dev"

allow_failures:
# Dev-master is allowed to fail.
- env: STABILITY="dev"

before_install:
- if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi
- if ! [ -z "$STABILITY" ]; then composer config minimum-stability ${STABILITY}; fi;
- if ! [ -z "$DEPENDENCIES" ]; then composer require --no-update ${DEPENDENCIES}; fi;

install:
- travis_retry composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
# To be removed when this issue will be resolved: https://github.com/composer/composer/issues/5355
- if [[ "$COMPOSER_FLAGS" == *"--prefer-lowest"* ]]; then composer update --prefer-dist --no-interaction --prefer-stable --quiet; fi
- composer update ${COMPOSER_FLAGS} --prefer-dist --no-interaction
- vendor/bin/simple-phpunit install

script:
- composer validate --strict --no-check-lock
- $TEST_COMMAND

after_success:
Expand Down
6 changes: 3 additions & 3 deletions Readme.md
Expand Up @@ -24,13 +24,13 @@ Just run the command like below:

```bash
# Example
./vendor/bin/translation-converter [input_dir] [output_dir] [format]
./vendor/bin/translation-converter translation:convert [input_dir] [output_dir] [format]

# Convert from JMSTranslationBundle
./vendor/bin/translation-converter app/Resources/translations app/Resources/translations-new jms
./vendor/bin/translation-converter translation:convert app/Resources/translations app/Resources/translations-new jms

# Convert from Yaml
./vendor/bin/translation-converter app/Resources/translations app/Resources/translations-new yml
./vendor/bin/translation-converter translation:convert app/Resources/translations app/Resources/translations-new yml
```

### Documentation
Expand Down
22 changes: 10 additions & 12 deletions composer.json
Expand Up @@ -10,15 +10,15 @@
],
"require": {
"php": "^5.5 || ^7.0",
"php-translation/symfony-storage": "^0.3.2",
"symfony/console": "^2.7 || ^3.0",
"symfony/yaml": "^2.7 || ^3.0",
"symfony/finder": "^2.7 || ^3.0",
"symfony/config": "^2.7 || ^3.0"
"php-translation/symfony-storage": "^1.0.1",
"symfony/console": "^2.7 || ^3.0 || ^4.0",
"symfony/yaml": "^2.7 || ^3.0 || ^4.0",
"symfony/finder": "^2.7 || ^3.0 || ^4.0",
"symfony/config": "^2.7 || ^3.0 || ^4.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.5 || ^6.2",
"php-translation/symfony-bundle": "^0.4"
"symfony/phpunit-bridge": "^4.0",
"php-translation/symfony-bundle": "^0.8"
},
"autoload": {
"psr-4": {
Expand All @@ -31,17 +31,15 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml"
"test": "vendor/bin/simple-phpunit",
"test-ci": "vendor/bin/simple-phpunit --coverage-text --coverage-clover=build/coverage.xml"
},
"bin": [
"src/translation-converter"
],
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "0.1-dev"
"dev-master": "1.0-dev"
}
}
}
4 changes: 2 additions & 2 deletions src/Command/ConvertCommand.php
Expand Up @@ -53,14 +53,14 @@ protected function execute(InputInterface $input, OutputInterface $output)

if (null === $format = $input->getOption('format')) {
$formats = array_unique($formats);
if (count($formats) !== 1) {
if (1 !== count($formats)) {
throw new \InvalidArgumentException('More than one format found. Please specify a format with --format=xxx');
}
$format = reset($formats);
}

$reader = $this->getReader($format);
$converter = new Converter($reader, $format === 'jms' ? 'xlf' : $format);
$converter = new Converter($reader, 'jms' === $format ? 'xlf' : $format);
$converter->convert($input->getArgument('input_dir'), $input->getArgument('output_dir'), array_unique($locales));
}

Expand Down
13 changes: 13 additions & 0 deletions src/Loader/TranslationLoader.php
Expand Up @@ -43,8 +43,21 @@ public function __construct(LoaderInterface $loader, $format)
*
* @param string $directory the directory to look into
* @param MessageCatalogue $catalogue the catalogue
*
* @deprecated Use read instead.
*/
public function loadMessages($directory, MessageCatalogue $catalogue)
{
return $this->read($directory, $catalogue);
}

/**
* Loads translation messages from a directory to the catalogue.
*
* @param string $directory the directory to look into
* @param MessageCatalogue $catalogue the catalogue
*/
public function read($directory, MessageCatalogue $catalogue)
{
if (!is_dir($directory)) {
return;
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/JmsReader.php
Expand Up @@ -71,11 +71,11 @@ public function load($resource, $locale, $domain = 'messages')
}
if ($approved = (string) $trans->attributes()->approved) {
$text = (string) $approved;
$meta['notes'][] = ['category' => 'approved', 'content' => $text == 'yes' || $text == 'true' ? 'true' : 'false'];
$meta['notes'][] = ['category' => 'approved', 'content' => 'yes' == $text || 'true' == $text ? 'true' : 'false'];
}

foreach ($trans->target->attributes() as $name => $value) {
if ($name === 'state') {
if ('state' === $name) {
$meta['notes'][] = ['category' => 'state', 'content' => (string) $value];
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Service/Converter.php
Expand Up @@ -44,6 +44,7 @@ public function __construct(LoaderInterface $reader, $format)
{
$this->reader = new TranslationLoader($reader, $format);
$this->writer = new TranslationWriter();
$this->writer->disableBackup();
$this->writer->addDumper('xlf', new XliffDumper());
}

Expand Down
14 changes: 13 additions & 1 deletion src/translation-converter 100644 → 100755
Expand Up @@ -10,7 +10,19 @@
* file that was distributed with this source code.
*/

require __DIR__.'/../vendor/autoload.php';
// This sucks.. we have to try to find the composer autoloader. But chances
// are, we can't find it this way. So we'll do our bestest
$paths = array(
__DIR__ . '/../vendor/autoload.php',
__DIR__ . '/../../../autoload.php',
);

foreach($paths as $path) {
if (file_exists($path)) {
include $path;
break;
}
}

use Symfony\Component\Console\Application;

Expand Down
1 change: 1 addition & 0 deletions tests/Functional/Service/ConverterTest.php
Expand Up @@ -21,6 +21,7 @@
class ConverterTest extends TestCase
{
protected static $fixturesDir;

protected static $outputDir;

public static function setUpBeforeClass()
Expand Down

0 comments on commit 34d7334

Please sign in to comment.