i18n_string translations could be handled by this module. The https://drupal.org/project/language_fallback module's 7.x-2.x branch does this, so I've created the attached patch that is based on the code from there.

To be honest, these two projects ought to merge probably. Language Hierarchy seems to me to use the most sensible approach generally, but doesn't quite cover all the same areas as Language Fallback's 7.x-2.x branch. But that's covered over in #2145151: Consider deprecating language_hierarchy in favor of entity_language_fallback.

Comments

james.williams created an issue. See original summary.

james.williams’s picture

StatusFileSize
new8.46 KB

Sorry, that last patch missed the new class file. Take 2!

rafalenden’s picture

Status: Active » Needs review
james.williams’s picture

StatusFileSize
new8.5 KB

Fixed a PHP notice caused by a slight difference between language hierarchy ancestors behaviour and language fallback chain behaviour.

steven jones’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

This could do with some tests.

steven jones’s picture

Issue tags: +ComputerMinds

Adding a tag so someone at ComputerMinds can pick this up.

james.williams’s picture

Since i18n 7.x-1.12, there is a i18n_string_textgroup_cached class that is used instead of i18n_string_textgroup_default for some i18n string objects (namely, fields), which the above patch(es) will not touch. A solution for language fallback (or at least Amazee Labs' fork of it) exists here: https://github.com/AmazeeLabs/language_fallback/commit/4fadff1ac937c11c7... - given that our patches are based on the Language Fallback work, this work would probably do the trick for LH too.

https://github.com/AmazeeLabs/language_fallback/commit/014d877040cfd9133... might also be necessary too, I'm not sure.

james.williams’s picture

StatusFileSize
new15.26 KB

Here's a patch that includes support for the cached strings, based on the work mentioned above. Still needs tests, but one thing at a time, eh? :-)

james.williams’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new20.72 KB

And here's a patch that actually tests our use of i18n_string, based on the tests in i18n_string itself and the existing LH tests :-)

steven jones’s picture

Status: Needs review » Needs work

@james.williams thanks very much for the patch and tests!

Could you provide a patch that has just the tests please, and not the fix/feature then we can see that the tests do indeed catch the fact that we don't get the expected behavior.

Also, a quick review of the patch:

+++ b/tests/language_hierarchy.test
@@ -378,3 +378,121 @@ class LanguageHierarchyStringTranslationWebTestCase extends LanguageHierarchyBas
+    // Check if i18n_string() works as expected.
+    $parent_translation = i18n_string_translate($name, 'NOT FOUND', array('langcode' => $parent_langcode));
+    $this->assertTrue($string != $translation && $parent_translation == $translation, 'i18n_string() works for parent.');
+
+    // Check if inheritance of i18n_string() works as expected.
+    $child_translation = i18n_string_translate($name, 'NOT FOUND', array('langcode' => $child_langcode));
+    $this->assertTrue($string != $translation && $child_translation == $translation, 'i18n_string() inherited from parent.');
+
+    // Check if translated string for child language works as expected.
+    $child_translation2 = i18n_string_translate($name, 'NOT FOUND', array('langcode' => $child_langcode2));
+    $this->assertTrue($string != $translation2 && $child_translation2 == $translation2, 'i18n_string() with translation for child.');

I'd suggest changing the comments here to indicate what is expected, rather than leaving the reader to work out what the intention was. Something like:

// Check if inheritance of i18n_string() works as expected: no specific translation for this child language, so translation in parent language returned.

etc.

james.williams’s picture

StatusFileSize
new5.63 KB
new20.96 KB

Et voilà.

james.williams’s picture

Status: Needs work » Needs review

The last submitted patch, 11: language-hierarchy-i18n_strings-2565711-11-only-tests.patch, failed testing.

steven jones’s picture

Status: Needs review » Fixed

Lovely stuff, thanks for the patch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.