Multilingual site - i18n+i18nviews+Metatag+metatag_views. Language as suffix(site.com/en).

Internationalization: i18n.module
------------------------------------------------------------------------------
All default configurations may be translated using the Internationalization
(i18n) module. The custom strings that are assigned to e.g. the "Global: Front
page" configuration will show up in the Translate Interface admin page
(admin/config/regional/translate/translate) and may be customized per language.
---------------------------------------------------------------------------------
This work only for default configuration from Metatag group, but for tags in custom views I can't translate meta tags through translate interface.

Also I can't add translation through path tab - multiligual path's not supported :(.

How to resolve this problems?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna’s picture

Title: Meta tags attached to custom views aren't translated, i18n » i18n support for Metatag submodules (Views, Contrib, Panels)
Issue tags: +D7 stable release blocker

Clarifying the title. This needs to be fixed for the final 1.0 release.

yang_yi_cn’s picture

strings in Metatag: Context are also not translatable.

DamienMcKenna’s picture

Title: i18n support for Metatag submodules (Views, Contrib, Panels) » i18n support for Metatag submodules (Views, Context, Panels)

Doh, wrote the wrong word.

yang_yi_cn’s picture

FileSize
1.98 KB

created a patch for the metatag_context module (note that I made the patch on metatag module level).

This patch adds the i18n_string_update() part in add/edit admin forms of the Metatag Context module to allow translations, and pulls the translated value when display.

yang_yi_cn’s picture

FileSize
4.09 KB

after some thoughts I think it's better to have the "context" part in the i18n text string name to avoid namespace conflicts with other metatag modules.

$name = 'metatag:context:' . $context->name . ':' . $key;

Patch re-rolled.

yang_yi_cn’s picture

FileSize
2.01 KB

sorry, the previous patch included some unnecessary stuff related to entity_translation.

Use this one instead.

jorgemaestre’s picture

#6 Thanks yang_yi_cn, patch is working fine for me.

DamienMcKenna’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, metatag-1986032-6.patch, failed testing.

moonray’s picture

This patch only fixes Metatag: Context, and not Metatag: Panels or Metatag: Views yet.
It's a good start, but if you're trying out the patch, it's something to be aware of.

DamienMcKenna’s picture

DamienMcKenna’s picture

Component: Code » Multilingual/intl
N20’s picture

Patch in #6 failed for me. I think it is important to have Metatag play nice together with transleted contexts. At the moment i can not translate the Metatags for any View.

vflirt’s picture

Hi,
I have similar issue but i needed panels. As metatag panels module is almost ready to implement the translation I added jus a few more lines to get the strings to appear in the translation interface :

changed metatag_panels_form_submit as :

function metatag_panels_form_submit($form, $form_state) {
  $conf = array(
    'enabled' => $form_state['values']['metatags_enabled'],
    'metatags' => $form_state['values']['metatags'],
  );

  $form_state['handler']->conf['metatag_panels'] = $conf;

  if ($conf['enabled']) {
    $handler = $form_state['handler'];
    $instance = 'panels:' . $handler->task . ':' . $handler->subtask . ':' . $handler->name;
    foreach ($conf['metatags'] as $field => $item) {
      $name = "metatag:" . $instance . ":" . $field;
      i18n_string_update($name, $item['value']);
    }
  }
}

and then in metatag_panels_ctools_render_alter i had to change
$instance = 'panels:' . $handler->name;
to
$instance = 'panels:' . $handler->task . ':' . $handler->subtask . ':' . $handler->name;
as handler->task and handler->subtask give a bit more information where that text come from in the translation inteface.

handler->name is unique so even if stick to default of $instance = 'panels:' . $handler->name; it will be cool .

This has its issues as deleting page/variant will not remove the strings , can't refresh the strings from the administration and so on .
Maybe we could implement something as i18n_panels module does (with the panels uuid patch and ctools-uuis_for_exported_object patch) though they rely on uuid as key but as said the $handler->name is unique and adding task and subtask provide enough meaningful information so when translation the text to have proper information where this text is actually used.

Kind Regards,
Dobromir

stijndmd’s picture

Considering Metatag Views:
Since the only one of the defaults here that isn't translatable is the description, here is kind of an unclean quick fix to make your view description translatable.
I know it's far from ideal, this fix, but if you're also in a hurry and need this now...

Tharna’s picture

FileSize
1.03 KB

Made this into a patch with a small change of requiring this patch to fix some notices.

alcroito’s picture

Issue summary: View changes
FileSize
1.39 KB

Attaching patch with changes proposed in #14, for Panels i18n.

alcroito’s picture

Attaching modified patch for panels i18n, that:
1) Checks for existence of i18n_string before trying to update the translation strings.
2) Removes the updated strings if the display / handler / variant is removed.

alcroito’s picture

FileSize
2.83 KB

Hiding old patches.
Attaching new patch that uses function_exists to check for i18n_string, to be more in correspondence with the code used throughout the module.

DamienMcKenna’s picture

pingwin4eg’s picture

#6 patch for metatag_context works good with metatag 7.x-1.0-beta9.

izus’s picture

Version: 7.x-1.0-beta7 » 7.x-1.0-beta9
Category: Bug report » Feature request
Status: Needs work » Needs review
FileSize
2.42 KB

Hi,
for some reason (files headers?), i couldn't apply #19
so i did it manually. and it worked fine for me, i can now have access to strings for translation in the metatag text group
here is the new generated patch file
Thanks

Thytane’s picture

Hello,

I tried the patch for metatag_panels on #22.
Patch OK. No errors when patching.

Just a little trouble if we use i18n feature for panels in a install profile. It's OK to have trads for metatags on panels but if the website is installed by a profile, there is one more action to do.

Translate backoffice said that it doesn't know the metatags strings unless you validate a second time your page_manager configuration. After that it's OK, the string is known and the traduction passed.

Thytane’s picture

Status: Needs review » Needs work
Thytane’s picture

A last thing, this patch (#22) is only for metatag_panels. It would be so great if it's possible to have a similar feature for metatag_views.
The 2 demands are really closed.

Thanks

izus’s picture

Status: Needs work » Needs review
FileSize
4.99 KB

hi,
following patch takes into account both panels and views.
did you try to refresh strings admin/config/regional/translate/i18n_string beofre testing ?
thx

Nick Robillard’s picture

Confirmed that patch in #6 works for Context translations

izus’s picture

Ok
here is a patch for panels views and context.
its just a merge of #6 and #26
Thanks

izus’s picture

Version: 7.x-1.0-beta9 » 7.x-1.x-dev
le72’s picture

What about taxonomy?

izus’s picture

hi,
i had an error with #28 for panel :
"Invalid argument supplied for foreach() metatag_panels.module:188"
following patch corrects it

maijs’s picture

I just filed a bug report regarding the fact that Metatag Views module does not allow user to set per-display Metatag settings (see #2289139 - Metatag settings cannot be set for each views display separately). A patch in #31 translates Metatag views settings in the same manner, saving a translation per view, ignoring a display name (translation context is view:[view-name]:[metatag-field]).

On the assumption that #2289139 is committed and that Metatag settings can be set per display, I'm attaching a patch that takes a patch from #31 and adds support for default and overridden Metatag option states. That is, if Metatag option is default (applies to all displays), translation context includes only view name (view:[view-name]:[metatag-field]). If Metatag option is overridden (applies only to one display), then translation context also includes display name (view:[view-name]:[display-name]:[metatag-field]).

DamienMcKenna’s picture

Removing this from the 1.0 blocker release, we'll get back to it after the rest of the module is stable. That said, the patch looks good and I appreciate all of the work being put into it, I just want to wait 'til the rest of the module is more stable.

marcusx’s picture

Tested this without any side effects. Works great.

jlmainguy’s picture

Hi everyone, I have applied the latest patch and I'm still getting a "Cannot refresh strings for Metatag" message when trying to refresh the strings. I see the translatable text from my Frontpage Global description meta tag, but nothing from my contexts tags (paths). Is anyone else still experiencing this issue?

sylus’s picture

The latest patch wasn't applying for me on latest dev post v1.4 so attaching updated patch with slightly modified logic to metatag_views as $saved_metatags variable was removed in dev.

DamienMcKenna’s picture

m33_nft’s picture

litle fix for patch #36

foreach ($context->reactions['metatag_context_reaction']['metatags']['und'] as $field => $item) {
$name = "metatag:context:" . $context->name . ":" . $field;
i18n_string_update($name, $item['value']);
}

JulienThomas’s picture

FileSize
3.14 KB

Thanks for this patch.

However, I faced the same issue as #1781232 and thus site went simply down for non-English pages that were having overridden metatags.

As a safety measure, it may be better to encapsulate call to i18n_string_translate() (as suggested in #1781232)

I attached such a patch

Status: Needs review » Needs work

The last submitted patch, 40: metatag-n1986032-40.patch, failed testing.

oskylark’s picture

Patch #39 - I've only tested for metatag_views but perhaps related to the #38 fix, I need to use $metatags[LANGUAGE_NONE] for the final i18n_string_update loop in function options_submit in metatag_views_plugin_display_extender_metatags.inc i.e.

        foreach ($metatags[LANGUAGE_NONE] as $field => $item) {
          $name = "metatag:" . $instance . ":" . $field;
          i18n_string_update($name, $item['value']);
        }

Making this change the saved metatag strings appear in Translate interface as required.

The last submitted patch, 32: metatag-panels-views-context-i18n-1986032_32.patch, failed testing.

robinudev’s picture

Any progress on this issue?

rv0’s picture

Status: Needs work » Needs review
FileSize
3.37 KB

Working re-roll of the metatag_views patch:

DamienMcKenna’s picture

@rv0: Thanks for the patch.

Could someone please give the patch in #47 a test run to see how well it works? Is there anything that we could add to README.txt to help explain how the functionality works?

rv0’s picture

Just some extra info:
the strings are entered into the i18n system when the metatag part in a view is submitted.
afterwards they are available for translation.

Sadly there is no automated mechanism in this patch to enter all existing views metatags in the i18n system. It would be possible to write though, but for the 6 views pages where I needed it it wasn't worth the effort.

So the functionality could use improving, but it doesn't really have to be a blocker for this patch (might as well be handled in a follow up)

DamienMcKenna’s picture

FileSize
8.02 KB

I've rolled in yang_yi_cn's patch from #6 into rv0's patch from #47, refactored it a bit so that there were two new functions to handle translations, and added similar support for Metatag:Panels. Please help test this. Thanks!

Status: Needs review » Needs work

The last submitted patch, 50: metatag-n1986032-50.patch, failed testing.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
10.34 KB

Lets see if the tests pass now.

yang_yi_cn’s picture

The last patch doesn't apply cleanly to 7.x-1.6. I reviewed the rejected ones and it looks they are mostly blank space differences. There's really just one difference:

Index: metatag_context/metatag_context.test
===================================================================
--- metatag_context/metatag_context.test	(revision 30954)
+++ metatag_context/metatag_context.test	(working copy)
@@ -25,6 +25,7 @@
    * Prepares the testing environment
    */
   public function setUp(array $modules = array()) {
+    $modules[] = 'context';
     $modules[] = 'metatag_context';
     parent::setUp($modules);

Do we really need add the 'context' module in the test?

DamienMcKenna’s picture

@yang_yi_cn: Thanks. I find adding the dependencies helps ensure that they're all enabled - it may not strictly be necessary, but it doesn't hurt having it there.

DamienMcKenna’s picture

FileSize
9.72 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, 55: metatag-n1986032-55.patch, failed testing.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
11.07 KB

Doh! Fixed the syntax goof in the Context tests file, and fixed some issues with those tests.

DamienMcKenna’s picture

Could someone please help test the latest patch? Thanks.

DamienMcKenna’s picture

DamienMcKenna’s picture

FileSize
12.49 KB

Based upon feedback in #2113501: Translated global metatag defaults do not display (show originals instead), I'm going to try out removing the $instance portion of the translation contexts, so that the context for a title would be "global:description" instead of e.g. "global:frontpage:description".

Status: Needs review » Needs work

The last submitted patch, 60: metatag-n1986032-60.patch, failed testing.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
12.51 KB

Copy/paste fail.

Status: Needs review » Needs work

The last submitted patch, 62: metatag-n1986032-62.patch, failed testing.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
12.55 KB

I'll eventually get the hang of this search/replace thing :(

DamienMcKenna’s picture

FileSize
12.63 KB

Found another occurrence of metatag_translate() being called.

DamienMcKenna’s picture

DamienMcKenna’s picture

FileSize
10.6 KB

Rerolled.

DamienMcKenna’s picture

FileSize
12.63 KB

I made some further improvements.

  • DamienMcKenna committed 5b8eb3d on 7.x-1.x
    Issue #1986032 by DamienMcKenna, izus, yang_yi_cn, Placinta, maijs,...
DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. Thanks everyone!

Status: Fixed » Closed (fixed)

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

nlambert’s picture

Status: Closed (fixed) » Needs work

I think there might still be a problem.

I've added a meta description to my variant: http://take.ms/dPMpK

Then I added another to another Panels Page.

The second is overriding the first: http://take.ms/QyAOc

I see the context is "metatag:metatag:description". Should this be "metatag:metatag:description:$pid" or something similar?

I didn't dive into the code, and haven't read every comment in this thread but I think it might be right to reopen this issue. Maybe the right procedure would be to open another ticket? Not sure. Let me know.

VISIOS’s picture

Same problem here as in #72. This might be a serious blocker because all of my custom title metatags in the translated language have been overwritten . Don't try this on production sites :)

Can anybody confirm this bug?

DamienMcKenna’s picture

FYI I'm working on tests to confirm everything's where it should be, I'm hoping to have a working patch tomorrow sometime, then we can haggle on how it should work and fix the things that aren't working right.

chegor’s picture

The same problem as in as in #72. For me that's in views. One context metatag:description (or metatag:og:description f.e.) for all views.

DamienMcKenna’s picture

Status: Needs work » Closed (fixed)