Often we need to synchronize locale strings between environments. Via the interface this is a time consuming job so I created this drush script. Perhaps this can be included into drush core?

Otherwise I'll make it a separate project.

Importing can take quite a while as the drupal po import is quite slow. I don't think this is because anything is wrong in the script, but perhaps someone with more experience in drush can check up on that.

Comments

gábor hojtsy’s picture

Is it possible to look at this in patch form?

Johnny vd Laar’s picture

StatusFileSize
new0 bytes

Sure but the entire change is a single file that you can just drop in your .drush folder.

gábor hojtsy’s picture

Empty patchfile?

Johnny vd Laar’s picture

StatusFileSize
new7.57 KB

I'm sorry

gábor hojtsy’s picture

Status: Active » Needs work

Thanks! A quick review:

+++ b/commands/core/locale.drush.incundefined
@@ -0,0 +1,202 @@
+      return dt('Exports the Drupal Locale as PO files.');
...
+    'description' => 'Exports the Drupal Locale as PO files.',
...
+    'description' => 'Imports a Drupal Locale PO file.',
...
+      'drush locale-import project.po nl default' => 'Import a locale po file into the dutch default group.',

Drupal never calls these "Drupal Locale"'s and especially not Drupal Locale PO files. I think the text could use some definite polish.

+++ b/commands/core/locale.drush.incundefined
@@ -0,0 +1,202 @@
+      'drush locale-dump' => 'Save all locale po files to the directory above Drupal root.',
...
+      'result-directory' => array(
+        'description' => 'Save to a directory. The directory should be writable by drush. If --result-directory is omitted then date based directory will be created under ~/drush-backups directory.',
+        'example-value' => '/path/to/file',
+        'value' => 'optional',

These two looks like entirely contradicting about the default location of the file?!

+++ b/commands/core/locale.drush.incundefined
@@ -0,0 +1,202 @@
+        'description' => 'The language group of the po file to import.',

There is no "language group" in core. Eg. the API docs on the import function say "Text group to export PO file from (eg. 'default' for interface translations).". It is not about a group of languages, but a group of source strings per their role in the system.

+++ b/commands/core/locale.drush.incundefined
@@ -0,0 +1,202 @@
+    'description' => 'Copy and import source locale to target locale. Transfers via rsync.',

This could use more polish as well. Although the functionality is implemented by locale module, this is not really something we call locale anywhere. It is "interface translations" for "languages". Not locale :) If you look through all the UI of the locale module, the word locale would AFAIR never even appear.

+++ b/commands/core/locale.drush.incundefined
@@ -0,0 +1,202 @@
+      $output = _locale_export_po_generate($languages[$language], _locale_export_get_strings($languages[$language], $group));

This will work in Drupal 6 and 7. I don't know about policy for Drupal 8 support, but this definitely does not work there.

+++ b/commands/core/locale.drush.incundefined
@@ -0,0 +1,202 @@
+ * Command callback. Imports a Drupal textgroups in a set language.

"Imports a Drupal textgroups" again clearly needs some text polish.

+++ b/commands/core/locale.drush.incundefined
@@ -0,0 +1,202 @@
+function drush_locale_import($filename, $language, $group) {
+  $mode = drush_get_option('import-mode', LOCALE_IMPORT_OVERWRITE);
+  $languages = language_list('language');
+
+  if (!isset($languages[$language])) {
+    drush_log(dt("Language @language does not exist in your Drupal setup.", array('@language' => $language)), 'error');
+    return;
+  }

Drupal uses $langcode to refer to the language code and $language to refer to an object (eg. one in the list of the $languages array). You use $language to refer to a langcode.

moshe weitzman’s picture

Thanks for the patch and the review. I'm not sure if this is broadly useful enough for Drush core. We can discuss that. Meanwhile, it will need full unit tests in order to get into Drush core. See the other tests in the /tests folder. There is a README there. Also needs to work on D8/D7/D6.

moshe weitzman’s picture

And also needs a maintainer.

Johnny vd Laar’s picture

I must say that I haven't spent a lot of time on the wording of things so I will look into that.

But could something like this, if the texts would be better, be a possible addition to default drush? Or would it be better if I made it into a separate drush module?

Johnny vd Laar’s picture

Ok thanks, well I can spent some more time on fixing the wording and look at d6 and d8 but I might need some help with the test coverage.

But I guess first you'll need to decide upon if it even can be included. Otherwise I will only fix the wording and make it into a separate module with only d7 support for now.

moshe weitzman’s picture

Sorry, I won't give guarantees. I'd have to talk to the proposed maintainer about future features, his/her availability, etc.

Johnny vd Laar’s picture

okay and a maintainer, that would be someone who maintains a complete branch or just this one functionality?

moshe weitzman’s picture

A maintainer specifically for locale.drush.inc. jonhattan currently maintains pm, owen maintains runserver/quickdrupal, etc.

Johnny vd Laar’s picture

Well I am not really familiar with how drush works internally so perhaps someone more experienced is better for this.

steinmb’s picture

Hi
Useful drush addon. Any chance for a re-roll with changes mention in #5?

Johnny vd Laar’s picture

For my personal testing I've set up this sandbox: https://drupal.org/sandbox/johnnyvdlaar/1872144

The above string improvements are implemented there.

steinmb’s picture

Thanx! I'll have a look :)

greg.1.anderson’s picture

Version: 7.x-5.7 » 8.x-6.x-dev
Status: Needs work » Closed (won't fix)
Issue tags: +Needs migration

This issue was marked closed (won't fix) because Drush has moved to Github.

If this feature is still desired, you may copy it to our Github project. For best results, create a Pull Request that has been updated for the master branch. Post a link here to the PR, and please also change the status of this issue to closed (duplicate).

Please ask support questions on Drupal Answers.