Hi @all,

I'd really appreciate if the features module would be able add the correct context to translatables.

An example:

If you have the i18n_field and i18n_string modules installed, all field strings get contexts (e.g. "field_name:node_type:label" for the field label). If you now extract a translation template with potx, the feature module does not provide this context... and so an automated update of your translation catalog is not possible and you have to update all strings manually.

What do you think? Should the features module use/provide these contexts?

I'd appreciate your feedback

Thanx in advance & cheers

hctom

Files: 
CommentFileSizeAuthor
#19 features-ctx_support_for_translatables-1270742-17.patch3.86 KBJohnny vd Laar
PASSED: [[SimpleTest]]: [MySQL] 40 pass(es).
[ View ]
#17 features-ctx_support_for_translatables-1270742-17.patch3.86 KBJohnny vd Laar
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch features-ctx_support_for_translatables-1270742-17.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#14 features-ctx_support_for_translatables-1270742-14.patch3.86 KBJohnny vd Laar
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch features-ctx_support_for_translatables-1270742-14.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#11 features-ctx_support_for_translatables-1270742-11.patch3.92 KBTessa Bakker
PASSED: [[SimpleTest]]: [MySQL] 45 pass(es).
[ View ]
#10 features-ctx_support_for_translatables-1270742-10.patch2.69 KBJohnny vd Laar
Test request sent.
[ View ]
#9 features-ctx_support_for_translatables-1270742-9.patch2.68 KBcedric
Test request sent.
[ View ]
#7 D7-features-translations_field_context.patch5.42 KBj.muschalle
Test request sent.
[ View ]
#6 D7-features-translations_field_context.patch5.42 KBj.muschalle
Test request sent.
[ View ]
#4 D7-features-translations_field_context.patch2.24 KBj.muschalle
Test request sent.
[ View ]
#2 D7-features-translations_field_context.patch2.25 KBj.muschalle
Test request sent.
[ View ]

Comments

hctom’s picture

Hmmm... am I the only one who has this problem, or didn't anybody ever read this issue?!

j.muschalle’s picture

StatusFileSize
new2.25 KB
Test request sent.
[ View ]

Hi!

I have the same problem too and I created this patch to fix it. It adds context in the t() function when label and description of field are exported.

colan’s picture

Status:Active» Needs review
j.muschalle’s picture

StatusFileSize
new2.24 KB
Test request sent.
[ View ]

Little misstake about context name of a field.
Here the new patch

hefox’s picture

Status:Needs review» Needs work
+++ b/html/sites/all/modules/features/features.export.inc
@@ -512,13 +512,16 @@ function features_var_export($var, $prefix = '', $init = TRUE) {
-  $translatables = array_filter(array_unique($translatables));

What's the reason for removing the array_unique?

+++ b/html/sites/all/modules/features/features.export.inc
@@ -512,13 +512,16 @@ function features_var_export($var, $prefix = '', $init = TRUE) {
+    if(is_array($string)){
+    $output .= "{$indent}t(" . features_var_export($string["value"]) . ",array(),array('context' => '".$string["context"]."'));\n";
+    }else{
+    $output .= "{$indent}t(" . features_var_export($string) . ");\n";
+    }      ¶

Tab characters? Coding standards in general.

+++ b/html/sites/all/modules/features/includes/features.field.inc
@@ -113,10 +113,10 @@ function field_features_export_render($module, $data, $export = NULL) {
+        array_push ( $translatables , array("value" => $field['field_instance']['label'], "context" => $field['field_config']['field_name'].':'.$field['field_instance']['bundle'].':label'));

Coding standard (spaces) + why need array_push here?

j.muschalle’s picture

StatusFileSize
new5.42 KB
Test request sent.
[ View ]

Here, the new version of the patch.

For the unique array, I did a little helper function to have a unique multi array, maybe you have a better solution.
I don't know why I used array_push, I changed that! :)

For the tab, I resaved my patch with my no configurate gedit, sorry, I changed that too!

j.muschalle’s picture

StatusFileSize
new5.42 KB
Test request sent.
[ View ]

Here, the new version of the patch.

For the unique array, I did a little helper function to have a unique multi array, maybe you have a better solution.
I don't know why I used array_push, I changed that! :)

For the tab, I resaved my patch with my no configurate gedit, sorry, I changed that too!

j.muschalle’s picture

Status:Needs work» Needs review
cedric’s picture

StatusFileSize
new2.68 KB
Test request sent.
[ View ]

The patch in #7 works fine but the code is a little weird, especially the part that filters the array of translatables.

I re-rolled it and used a simpler approach of generating the t() calls in an array of strings, and then I filter duplicate lines.

ALSO: My patch adds support for translatables for the 'allowed values' of a select box. This could be a separate issue, but since allowed_values also need a special context, it is easier to do it in a single patch.

Johnny vd Laar’s picture

StatusFileSize
new2.69 KB
Test request sent.
[ View ]

The code in the last patch works but perhaps there should be a check whether the allowed values have empty labels or not. I've added that in the patch.

Tessa Bakker’s picture

Version:7.x-1.x-dev» 7.x-2.x-dev
StatusFileSize
new3.92 KB
PASSED: [[SimpleTest]]: [MySQL] 45 pass(es).
[ View ]

Here is the patch for Features 2, based on the #10 patch.

hefox’s picture

Status:Needs review» Needs work

the first changes contain some coding issues, should likely run it through coder

mpotter’s picture

Seems like this also generates the header comment text even if there aren't any translatables.

Johnny vd Laar’s picture

Status:Needs work» Needs review
StatusFileSize
new3.86 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch features-ctx_support_for_translatables-1270742-14.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Attached is a patch that fixes a bug in translating descriptions and fixes the coding style errors.

Status:Needs review» Needs work

The last submitted patch, features-ctx_support_for_translatables-1270742-14.patch, failed testing.

Johnny vd Laar’s picture

Hmm I can't seem to find anything wrong with my patch. Anyone with a clue?

Johnny vd Laar’s picture

Status:Needs work» Needs review
StatusFileSize
new3.86 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch features-ctx_support_for_translatables-1270742-17.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Another try then ;-)

Status:Needs review» Needs work

The last submitted patch, features-ctx_support_for_translatables-1270742-17.patch, failed testing.

Johnny vd Laar’s picture

Status:Needs work» Needs review
StatusFileSize
new3.86 KB
PASSED: [[SimpleTest]]: [MySQL] 40 pass(es).
[ View ]

Gah

Johnny vd Laar’s picture

Issue summary:View changes

Just formatting the text and fixing minor typos

Johnny vd Laar’s picture

What else is needed to get this included?

Boobaa’s picture

Issue summary:View changes
Status:Needs review» Reviewed & tested by the community

Works for me, thanks. Hopefully it'll get in soon!

hefox’s picture

Sorry just looking over this briefly, would this break any current translations of the items with added context?

mikran’s picture

Status:Reviewed & tested by the community» Needs work

Current translations just don't work when textgroup is anything but 'default'.

But t() (with context) is not how i18n_strings are translated so would this even work? Potx would produce a file with default translations mixed with translations with contexts but those would still be default translations, right? How would the import process go to separate the strings into different text groups?

cedric’s picture

@mikran : You are right that by itself this patch is not enough.

You also need to patch the string export and import modules so the context and textgroup is preserved the whole way around.

In our case, we are using the potx module to export translations which we patched and we use l10n_update to re-import which we also patched.

So for us a total of 3 patches was requires to get everything to 'work'.