Merge pull request #1573 from bburnichon/PHRAS-810

Reestablish geoname connection
This commit is contained in:
Benoît Burnichon
2015-11-20 11:10:57 +01:00
9 changed files with 114 additions and 31 deletions

View File

@@ -711,7 +711,7 @@ class Application extends SilexApplication
/**
* Return available language for phraseanet
*
* @return Array
* @return array
*/
public static function getAvailableLanguages()
{

View File

@@ -12,8 +12,14 @@
namespace Alchemy\Phrasea\Command\Developer;
use Alchemy\Phrasea\Command\Command;
use JMS\TranslationBundle\Logger\OutputLogger;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\Comparison\ChangeSet;
use JMS\TranslationBundle\Translation\ConfigBuilder;
use JMS\TranslationBundle\Translation\Updater;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class TranslationDumper extends Command
@@ -21,31 +27,99 @@ class TranslationDumper extends Command
public function __construct()
{
parent::__construct('translation:dump');
$this->setDescription('Dump translation files');
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setDescription('Dump translation files');
$this
->addArgument('locales', InputArgument::IS_ARRAY, 'The locales for which to extract messages.')
->addOption('dry-run', null, InputOption::VALUE_NONE, 'When specified, changes are _NOT_ persisted to disk.')
->addOption('keep', null, InputOption::VALUE_NONE, 'Define if the updater service should keep the old translation (defaults to false).')
;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
foreach (array_keys($this->container->getAvailableLanguages()) as $code) {
$builder = new ConfigBuilder();
$config = $builder->setLocale($code)
->setOutputFormat('xlf')
->setTranslationsDir(__DIR__ . '/../../../../../resources/locales')
->setScanDirs([
$this->container['root.path'].'/lib',
$this->container['root.path'].'/templates',
$this->container['root.path'].'/bin',
$this->container['root.path'].'/www',
])
->getConfig();
$this->container['translation-extractor.updater']->process($config);
$builder = new ConfigBuilder();
$builder
->setOutputFormat('xlf')
->setTranslationsDir(__DIR__ . '/../../../../../resources/locales')
->setScanDirs([
$this->container['root.path'].'/lib',
$this->container['root.path'].'/templates',
$this->container['root.path'].'/bin',
$this->container['root.path'].'/www',
])
;
if ($input->hasParameterOption('--keep') || $input->hasParameterOption('--keep=true')) {
$builder->setKeepOldTranslations(true);
} else if ($input->hasParameterOption('--keep=false')) {
$builder->setKeepOldTranslations(false);
}
$locales = $input->getArgument('locales');
if (empty($locales)) {
$locales = array_keys($this->container->getAvailableLanguages());
}
if (empty($locales)) {
throw new \LogicException('No locales were given, and no locales are configured.');
}
foreach ($locales as $locale) {
$config = $builder->setLocale($locale)->getConfig();
$output->writeln(sprintf('Extracting Translations for locale <info>%s</info>', $locale));
$output->writeln(sprintf('Keep old translations: <info>%s</info>', $config->isKeepOldMessages() ? 'Yes' : 'No'));
$output->writeln(sprintf('Output-Path: <info>%s</info>', $config->getTranslationsDir()));
$output->writeln(sprintf('Directories: <info>%s</info>', implode(', ', $config->getScanDirs())));
$output->writeln(sprintf('Excluded Directories: <info>%s</info>', $config->getExcludedDirs() ? implode(', ', $config->getExcludedDirs()) : '# none #'));
$output->writeln(sprintf('Excluded Names: <info>%s</info>', $config->getExcludedNames() ? implode(', ', $config->getExcludedNames()) : '# none #'));
$output->writeln(sprintf('Output-Format: <info>%s</info>', $config->getOutputFormat() ? $config->getOutputFormat() : '# whatever is present, if nothing then '.$config->getDefaultOutputFormat().' #'));
$output->writeln(sprintf('Custom Extractors: <info>%s</info>', $config->getEnabledExtractors() ? implode(', ', array_keys($config->getEnabledExtractors())) : '# none #'));
$output->writeln('============================================================');
/** @var Updater $updater */
$updater = $this->container['translation-extractor.updater'];
$updater->setLogger($logger = new OutputLogger($output));
if (!$input->getOption('verbose')) {
$logger->setLevel(OutputLogger::ALL ^ OutputLogger::DEBUG);
}
if ($input->getOption('dry-run')) {
/** @var ChangeSet $changeSet */
$changeSet = $updater->getChangeSet($config);
$output->writeln('Added Messages: '.count($changeSet->getAddedMessages()));
if ($input->getOption('verbose')){
/** @var Message $message */
foreach($changeSet->getAddedMessages() as $message){
$output->writeln($message->getId(). '-> '.$message->getDesc());
}
}
if ($config->isKeepOldMessages()) {
$output->writeln('Deleted Messages: # none as "Keep Old Translations" is true #');
} else {
$output->writeln('Deleted Messages: '.count($changeSet->getDeletedMessages()));
if ($input->getOption('verbose')){
foreach($changeSet->getDeletedMessages() as $message){
$output->writeln($message->getId(). '-> '.$message->getDesc());
}
}
}
return 0;
}
$updater->process($config);
}
$output->writeln('done!');
return 0;
}
}

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file date="2015-11-18T19:40:24Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<file date="2015-11-19T12:47:12Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>
@@ -1138,7 +1138,7 @@
<trans-unit id="007810133a83b7b3afb91124c6251b20b8b6d670" resname="Aucune description." approved="yes">
<source>Aucune description.</source>
<target state="translated">No caption</target>
<jms:reference-file line="70">actions/Bridge/element_list.html.twig</jms:reference-file>
<jms:reference-file line="69">actions/Bridge/element_list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="4024cf49635467f91f0bcd4f703e0440602a9e76" resname="Aucune entree pour le moment" approved="yes">
<source>Aucune entree pour le moment</source>
@@ -1781,12 +1781,12 @@
<trans-unit id="6e9445beaddb548587c6f275e49da38e9fc7b785" resname="Confidentialite : privee" approved="yes">
<source>Confidentialite : privee</source>
<target state="translated">Private</target>
<jms:reference-file line="86">actions/Bridge/element_list.html.twig</jms:reference-file>
<jms:reference-file line="85">actions/Bridge/element_list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="6c45b1287fc853dd348acfba612f3229746dc4f0" resname="Confidentialite : publique" approved="yes">
<source>Confidentialite : publique</source>
<target state="translated">Public</target>
<jms:reference-file line="88">actions/Bridge/element_list.html.twig</jms:reference-file>
<jms:reference-file line="87">actions/Bridge/element_list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="754164850f38c1ecdaf6b8ed894cb192bc36c5f4" resname="Configuration" approved="yes">
<source>Configuration</source>
@@ -9557,7 +9557,7 @@
<trans-unit id="fc97186645dc71dae8e3221c8ce53c56e6d611bf" resname="dans %category%" approved="yes">
<source>dans %category%</source>
<target state="translated">in %category%</target>
<jms:reference-file line="80">actions/Bridge/element_list.html.twig</jms:reference-file>
<jms:reference-file line="79">actions/Bridge/element_list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="dbfe8cf37a8d7b4941dd9f89e79302038b2bedef" resname="dans %feed_name%" approved="yes">
<source>dans %feed_name%</source>
@@ -12896,6 +12896,11 @@
<target state="new">unknown</target>
<jms:reference-file line="34">task-manager/task-editor/subdefs.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="9f273e321a1d1ea40251ab0a45f8ca8cbdd135da" resname="untitled">
<source>untitled</source>
<target state="new">untitled</target>
<jms:reference-file line="58">actions/Bridge/element_list.html.twig</jms:reference-file>
</trans-unit>
<trans-unit id="38ed031ff1a2d3f63b6415db3993741c54e41087" resname="update::Votre application necessite une mise a jour vers :" approved="yes">
<source>update::Votre application necessite une mise a jour vers :</source>
<target state="translated">Your application needs an update to :</target>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" xmlns:jms="urn:jms:translation" version="1.2">
<file date="2015-11-18T19:40:25Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<file date="2015-11-19T12:47:12Z" source-language="en" target-language="en" datatype="plaintext" original="not.available">
<header>
<tool tool-id="JMSTranslationBundle" tool-name="JMSTranslationBundle" tool-version="1.1.0-DEV"/>
<note>The source node in most cases contains the sample message as written by the developer. If it looks like a dot-delimitted string such as "form.label.firstname", then the developer has not provided a default message.</note>

View File

@@ -1101,7 +1101,7 @@
});
});
define([
require([
"jquery",
"common/geonames"
], function ($, geonames) {

View File

@@ -55,8 +55,7 @@
<a href='{{element.get_url}}' target="_blank">
{% endif %}
<span class="title">
{% set no_title = "untitled" %}
{{element.get_title|default(no_title|trans)}}
{{element.get_title|default('untitled'|trans)}}
</span>
{% if element.get_url != '' %}
</a>

View File

@@ -17,6 +17,7 @@ require.config({
backbone: "../assets/backbone-amd/backbone",
"jquery.ui.widget": "../assets/jquery-file-upload/jquery.ui.widget",
"jquery.cookie": "../assets/jquery.cookie/jquery.cookie",
"jquery.geonames": "../assets/geonames-server-jquery-plugin/jquery.geonames",
"jquery.treeview": "../assets/jquery.treeview/jquery.treeview",
"jquery.tooltip": "../include/jquery.tooltip",
"blueimp.loadimage" : "../assets/blueimp-load-image/load-image",
@@ -37,6 +38,10 @@ require.config({
deps: ["jquery"],
exports: '$.fn.cookie'
},
"jquery.geonames": {
deps: ["jquery"],
exports: '$.fn.geocompleter'
},
"jquery.tooltip": {
deps: ["jquery"],
exports: '$.fn.tooltip'

View File

@@ -17,7 +17,7 @@ require.config({
backbone: "../assets/backbone-amd/backbone",
i18n: "../assets/i18next/i18next.amd-1.6.3",
bootstrap: "../assets/bootstrap/js/bootstrap.min",
multiselect: "../assets/bootstrap-multiselect/dist/js/bootstrap-multiselect",
multiselect: "../assets/bootstrap-multiselect/js/bootstrap-multiselect",
"jquery.geonames": "../assets/geonames-server-jquery-plugin/jquery.geonames"
},
shim: {

View File

@@ -1,7 +1,7 @@
;
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([''], factory);
define(['jquery.geonames'], factory);
} else {
root.geonames = factory();
}