Problem/Motivation

It is not possible to set Metatags for different languages on the frontpage. The problem occurs if you have a frontpage that is no node. Most frontapges consist of views.

Proposed resolution

Using variables for saving the data, then we can use i18n_variable to translate these to various languages.

Remaining tasks

User interface changes

None.

API changes

Original report by [username]

Currently there is no option to set different descriptions or keywords depending on the language.
(for legacy issues whose initial post was not the issue summary)

Files: 
CommentFileSizeAuthor
#82 metatag-n1282620-82.patch5.05 KBDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]
#80 metatag-multilingual-support-1282620-68-rev1.patch4.57 KBzterry95
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]
#77 metatag-n1282620-77.patch4.67 KBDamienMcKenna
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]
#68 metatag-multilingual-support-1282620-68.patch5.15 KBPeacog
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es).
[ View ]
#63 multilingual_metatag-1282620-63.patch4.55 KBLukas von Blarer
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch multilingual_metatag-1282620-63.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#53 multilingual_metatag-1282620-53.patch4.67 KBidflood
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]
#51 multilingual_metatag-1282620-51.patch4.17 KBmgifford
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]
#45 metatag-1282620-45.patch4.17 KBmarcoka
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]
#28 multilingual_metatag-1282620-28.patch4.67 KBidflood
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]
#25 add_config-1282620-25.patch3.8 KBevanbarter
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]
#19 multilingual_metatag-1282620-19.patch4.63 KBidflood
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

Comments

tsvenson’s picture

Status:Active» Postponed (maintainer needs more info)

Please specify how exactly you need this. If your using Drupals built in multilingual support and the i18n module, each language version is saved as a separate node with separate fields, including metatags fields.

tsvenson’s picture

Status:Postponed (maintainer needs more info)» Active
jherencia’s picture

Yes, this does not happen with nodes, but in case you have 'node' url as front page you cannot specify different descriptions or keywords depending on language.

I think in D6 you could do this with multilingual variables.

idflood’s picture

I think jherencia is right. There needs to be i18n support for both description and keywords. This may only be required for "global" and "global: homepage" metatags settings.

I'm wondering if it wouldn't be better to implement i18n for all DrupalTextMetaTag, and maybe all metatags settings instead of just the "global" ones. Less special cases, more flexibility and hopefully not much negative side-effects.

mgifford’s picture

Subscribe. And ya, hopefully it's just a matter of the global & global: homepage tags.

datarazor’s picture

Essential, subscribing.
keywords: localization, language, translation.

mgifford’s picture

Tagging @datarazor's keywords.

tty11’s picture

Subscribe.
For information, no multitlingual support it's a mater for multilingual taxonomy term.

dimon00’s picture

One could write node content in another language without having to use i18n module.
It would be good to be able to set the meta tag of that specific node (or node type).

maxxer’s picture

Version:» 7.x-1.x-dev

bump! my understanding is this module is completely incompatible with entity translate....

renat’s picture

Looks like multilingual support can be gained relatively easy here, because there are special API module, Variable, just for that purpose. Usually it is enough to declare variables, which should be translatable, and it's translation can be done with Drupal standard tools.

As of #1, multilingual support can be useful for the front page, for panels and for nodes with entity-based translations.

mgifford’s picture

Can you document how this should be done?

maxxer’s picture

Apologies if this is off-topic, as this thread is specifically concerned with the Meta Tags module.
Indeed renat's suggestion in #11 would be a straight-forward solution.

But for anyone stumbling onto this thread looking for an alternative: we ended up using meta tags quick instead:

http://drupal.org/project/metatags_quick

Which adds core fields (you can also add custom fields) which by default are translatable.
For non node pages (views etc) there is ability to add path based meta tags per language.

If you're after something simple (i.e. just adding some field based meta), you can also go ahead and add a new field to your content type and use some simple code in template.php or a custom module.

As a basic illustrative example, this is to add some open graph tags, after we ran into exactly the same issue for localization with the og tags module.

$this_tag = array( $node->field_my_field[$lang][0]['value'],"custom_field_name");
$temp_tag = array(
    '#type' => 'html_tag',
    '#tag' => 'meta',
    '#attributes' => array(
      'property' => 'og:' . $this_tag[1],
'content' => $this_tag[0]
    ));
//Add meta tags to head
drupal_add_html_head($temp_tag, $this_tag[1]);

Note we have to define $lang and $node in template.php

Dave Reid’s picture

It is in fact off-topic. We are all very aware of the metatags_quick module so you don't need to continue to point it out in this issue queue.

idflood’s picture

The proposition from #11 to use the variable module made me want to try to implement it. It sounds relatively simple since just adding hook_variable_info() will make the variable translatable if the i18n_variable module is enabled. Then we must call variable_get_value and variable_set_value.

The problem is that metatag use its own table with some good caching going on. With this, I don't see any easy way to implement multilingual support. Any idea?
edit: i18n_string may be a better choice for this.

mgifford’s picture

Title:Add multitlingual support» Add multitlingual support to Meta tags
Issue tags:+i18n

The concerns are primarily with the front page or views, right? Each node should still be able to present node & language specific metatags, right?

idflood’s picture

With some inspiration from #11 this could be useful in these situations:
- global
- front page
- panels
- nodes with entity-based translations

epawel’s picture

Is there any chance to set different descriptions or keywords depending on domain ? Any help would be very appreciated

idflood’s picture

Status:Active» Needs work
StatusFileSize
new4.63 KB
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

#18: Please open a new issue with your feature request, I think it's related but out of the scope of this issue.

Here is some starting work. It's far from complete but I hope it's a step in the right direction. I'm not familiar with both metatag and i18n_string modules so if you can give some advice or continue some work on the patch don't hesitate.

Remaining tasks:
- do something in metatag_config_save($config), but what...
- pass the correct langcode to the new metatag_tt function when required
- certainly more things

Kristen Pol’s picture

@idflood - What version of metatag is the patch for? It doesn't seem to align with the latest version as there is no metatag.admin.inc file (there is a metatag_ui/metatag_ui.admin.inc though).

Can you reroll the patch for the latest version of the module?

Thanks!
Kristen

idflood’s picture

@Kristen Pol: The patch is against the 7.x-1.x branch. It still apply without a itch with the following commands. Tell me if I'm doing something wrong.

git clone --branch 7.x-1.x http://git.drupal.org/project/metatag.git
cd metatag
wget http://drupal.org/files/multilingual_metatag-1282620-19.patch
git apply multilingual_metatag-1282620-19.patch

But the patch does nothing right know. Some piece of code are still missing to make it working.

Kristen Pol’s picture

Ah... thanks for the clarification!

I'm writing a D7 i18n book right now and was hoping this would be fixed before February so I can say this works! ;) Right now, I'm just putting this issue page URL in the book so people can track it.

Unfortunately, I don't have time to try to understand the code and update the patch... though maybe in late February if it hasn't been fixed by then.

Thanks!
Kristen

7thkey’s picture

Subscribing.

Danny Englander’s picture

My use case for this functionality is I am using the Entity Translation Module so therefore I only have one node for many languages. I will be glad to test patches as they become available though it sounds like #19 is just a start. Thanks.

evanbarter’s picture

StatusFileSize
new3.8 KB
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

This is something we need on a site that's currently being developed by my company. I took the patch in #19 and addressed the "do something in metatag_config_save($config)" issue. This patch will allow you to create translations via the translation interface. I can't stress enough that this probably needs a ton more work and won't work for you (I've never touched Metatag or i18n before either), but it works for us on the narrow use case we needed to cover. Attached patch rolls #19 in, hopefully someone can keep this moving forward.

mgifford’s picture

Status:Needs work» Needs review

I want the bot to test this. Thanks @evanbarter & @idflood for your patches!

Status:Needs review» Needs work

The last submitted patch, add_config-1282620-25.patch, failed testing.

idflood’s picture

Status:Needs work» Needs review
StatusFileSize
new4.67 KB
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

Wow, @evanbarter that is great : ) I have tested your patch and it is working fine. There was 2 notices so I made a little change:
- added the '$options["instance"] = $metatag;' in metatag_get_value()
- added back the metatag.i18n.inc file. This remove notices I had in the translate interface page and it adds the "Metatag" group in the "Limit search to" select (admin/config/regional/translate/translate).

Status:Needs review» Needs work

The last submitted patch, multilingual_metatag-1282620-28.patch, failed testing.

Danny Englander’s picture

I applied the patch from #28 but I am not sure what to do next. I am using Entity Translation to Translate, that means one node for many languages. I have English set as my default language with metatags entered. (Keywords and Description).

  1. I clicked on my Translate tab in the node and edited my Spanish translation and entered metatags there but they do not get saved.
  2. I also went to "Translate interface > Strings" /admin/config/regional/translate/i18n_string, see the new checkbox for "Metatag" and refreshed the strings for that.
  3. I then went to "Translate interface > Translate" at: /admin/config/regional/translate/translate, selected metatag but do not see anything to translate. At any rate, I cannot see my site editors having to do this to translate metatags, I think ideally it would be done at the node level but I am using Entity Translation...
idflood’s picture

Status:Needs work» Needs review
Issue tags:-language, -i18n, -translation, -localization

Status:Needs review» Needs work
Issue tags:+language, +i18n, +translation, +localization

The last submitted patch, multilingual_metatag-1282620-28.patch, failed testing.

idflood’s picture

@highrockmedia: The patch in #28 only focus on general metatags and should not handle entity specific tags.

I think it may involve large change to handle such case. For instance a new 'language' field in the metatag table may be required. So maybe it is better to open a new issue for this.

edit: The tests pass on my local setup, don't know what makes the bots go red.

kemo1’s picture

Subscribing.

rooby’s picture

Not sure if this should be part of this issue or a separate issue but it would be good to also include the lang attribute of metatags.

The lang attribute would also be nice to have on single langauge sites however if the site is using LANGUAGE_NONE everywhere metatags would have no way of knowing what language it should be.
Unless a language selector was given in the admin UI or something.

@kemo1:
Try out the big green 'Follow' button at the top of the issue.

rooby’s picture

Also note that xml:lang is the preferred attribute but both xml:lang and lang can be used at the same time if desired.

mgifford’s picture

Status:Needs work» Needs review
Issue tags:-language, -i18n, -translation, -localization

Status:Needs review» Needs work
Issue tags:+language, +i18n, +translation, +localization

The last submitted patch, multilingual_metatag-1282620-28.patch, failed testing.

Kristen Pol’s picture

Title:Add multitlingual support to Meta tags» Add multilingual support to Meta tags
marcoka’s picture

can anyone acces the patches? i can click the url but noting happens.

rooby’s picture

The patch is in comment #28 above, just get it from there.

marcoka’s picture

ok, i tested #28 and it worked. the global frontpage string can now be translated using i18n string translation ui "admin/config/regional/translate/translate"
i patched the latest 7.x dev i cloned with gitclone

mgifford’s picture

Status:Needs work» Needs review
Issue tags:-language, -i18n, -translation, -localization

Status:Needs review» Needs work
Issue tags:+language, +i18n, +translation, +localization

The last submitted patch, multilingual_metatag-1282620-28.patch, failed testing.

marcoka’s picture

StatusFileSize
new4.17 KB
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

hm. retest, just patch formatting change
ignore this patch

stop retesting, wont work, read the test log

Fatal error: Call to undefined function metatag_config_load_with_defaults() in /var/lib/drupaltestbot/sites/default/files/checkout/sites/default/modules/metatag/metatag.test on line 26
FATAL MetaTagsUnitTest: test runner returned a non-zero error code (255).
mgifford’s picture

Sorry, I read "ok, i tested #28 and it worked.", then went to the test log and figured that the bot might have been bust.

You going to send the latest patch to get reviewed by the bot or is that bust too?

marcoka’s picture

the patch i attached should be ignored :). i think there is something wrong with the simpletest.
mgifford. i used #28 to and it works here too.

colan’s picture

colan’s picture

Title:Add multilingual support to Meta tags» Add multilingual support (for general tags only) to Meta Tags

Updating title.

josebc’s picture

subscribe

mgifford’s picture

Status:Needs work» Needs review
StatusFileSize
new4.17 KB
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

trying to re-role #28 to see if we can make the bot happier.

Status:Needs review» Needs work

The last submitted patch, multilingual_metatag-1282620-51.patch, failed testing.

idflood’s picture

Status:Needs work» Needs review
StatusFileSize
new4.67 KB
FAILED: [[SimpleTest]]: [MySQL] 0 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

Let's try again but this time with a module_load_include('module', 'metatag');. The function exists in metatag.module, so this should go a little bit further.

Status:Needs review» Needs work

The last submitted patch, multilingual_metatag-1282620-53.patch, failed testing.

guysaban’s picture

For those who need Entity support for Metatag see: http://drupal.org/node/1688286

DamienMcKenna’s picture

This needs to work in 1.0.

DamienMcKenna’s picture

This needs work:

  • It shouldn't add Variables as a new dependency, especially when it isn't even used.
  • The DrupalDefaultMetaTag class and DrupalListMetaTag class' getValue() methods shouldn't have the $name line as that value isn't used anywhere.
  • The metatag_tt() function needs a full comment explaining what it's for, its parameters and what is returned.
DamienMcKenna’s picture

Also, did the last patch forget to include the metatag.i18n.inc file from earlier patches?

DamienMcKenna’s picture

Lukas von Blarer’s picture

Is this issue fixed in this case?

DamienMcKenna’s picture

@Lukas: no, the non-entity meta tags need work.

Lukas von Blarer’s picture

Obviously it's not... I am re-rolling this patch.

Lukas von Blarer’s picture

StatusFileSize
new4.55 KB
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch multilingual_metatag-1282620-63.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

I tried to re-roll this patch, but it is not working yet. The strings are added, but when getting the values, the stings are not translated.

  • It shouldn't add Variables as a new dependency, especially when it isn't even used.
  • The DrupalDefaultMetaTag class and DrupalListMetaTag class' getValue() methods shouldn't have the $name line as that value isn't used anywhere.
  • The metatag_tt() function needs a full comment explaining what it's for, its parameters and what is returned.

I removed variable as a dependency.
The $name varible is used a few lines below.
The metatag_tt() function is still not documented.

Lukas von Blarer’s picture

What has to be done to fix this?

Kristen Pol’s picture

Does the patch in #63 work for anyone?

mlmsoftwarefactory’s picture

Multilingual meta tag for a single page is not possible but can we expand meta tag same in multilingual.
Is it possible?

Kristen Pol’s picture

@mlmsoftwarefactory I don't understand what you mean... can you give examples of the 2 different options?

Peacog’s picture

StatusFileSize
new5.15 KB
PASSED: [[SimpleTest]]: [MySQL] 11 pass(es).
[ View ]

Ok, I've made an attempt at re-rolling this patch. I reverted to the patch from #28 as it seemed the most complete. I made the changes requested in #57 and I renamed the metatag_tt() function to metatag_translate() since the old tt() function that it was presumably named for is deprecated. Let's see if this works.

plach’s picture

Status:Needs work» Needs review
DamienMcKenna’s picture

Status:Needs review» Needs work

Is there a reason to define the $name variable in the classes in metatag.inc? The variables aren't actually used.

DamienMcKenna’s picture

Title:Add multilingual support (for general tags only) to Meta Tags» Integration with i18n for per-language defaults
DamienMcKenna’s picture

valery86’s picture

Will this patch be included in the next Metatags version? If so, when is the next version planned to be released?

Thanks!

DamienMcKenna’s picture

@valery86: Please see #1860408: Release 7.x-1.0-beta5.

DamienMcKenna’s picture

Marked #1947100: Meta Tags + i18n as a duplicate.

zterry95’s picture

test patch of #68, works well for me.

Hope this can be embed into metatag core.

DamienMcKenna’s picture

Status:Needs work» Needs review
StatusFileSize
new4.67 KB
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]

Rerolled, and removed some unused $name variables.

DamienMcKenna’s picture

I'd love to commit this but I'm not sure it's working correctly? I installed i18n_strings v7.x-1.8, cleared the caches, went to admin/config/regional/translate/i18n_string where I rescanned the strings for Metatag but it returns this error:
Cannot refresh strings for Metatag.
Further, on the main Translate page (admin/config/regional/translate) it shows 0 translatable strings for Metatag.

Looking through the code I wonder has the i18n API changed since the patch was originally written?

DamienMcKenna’s picture

Status:Needs review» Needs work

I can't get this to do anything, some assistance would be appreciated :)

zterry95’s picture

StatusFileSize
new4.57 KB
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]

Here is the patch we create based on dev branch and it is actually running on our website.

The translation works well with this patch.

I help this can help to save your time:)

some steps for this.
1: add a metatag instance.
for keywords, input "test i18n"
2: Goto admin/config/regional/translate/translate
search "test i18n"
3: translate, game over.

Pls test it in mutilanguage site, with i18n installed and i18n_string enabled.

DamienMcKenna’s picture

Status:Needs work» Needs review

@zterry95: Did you forget to include the metatag.i18n.inc file in your patch?

DamienMcKenna’s picture

StatusFileSize
new5.05 KB
PASSED: [[SimpleTest]]: [MySQL] 21 pass(es).
[ View ]

The patch from #80 with the metatag.i18n.inc file from #77.

DamienMcKenna’s picture

So I *think* I was able to get this working right, but I'm not sure. It seems that any of the configurations assigned on admin/config/search/metatags can be translated, but the per entity object values, e.g. the values set on an individual node, cannot be translated. Is this how it should work? I think it might help to add some instructions to the README.txt file about it.

zterry95’s picture

Just take for example:
maybe for a node.

the description is : [node:title] | my string for translation
Then you can translate it as : [node:title] | 翻译后的字符串

so the translation for token [node:title] is handlered by i18n. we don't need to worry it.

DamienMcKenna’s picture

If someone else would care to review the patch in #82 I'll be more than happy to add it to the next beta.

DamienMcKenna’s picture

Status:Needs review» Fixed

Committed! A huge thanks to everyone who contributed to this, this really was a great example of community collaboration :-)

Please post follow-on tasks/bugs as new issues.

zterry95’s picture

cheers!

DamienMcKenna’s picture

Status:Fixed» Closed (fixed)

1.0-beta6 is out, so I'm closing this issue in the interest of keeping the issue queue clean.

valery86’s picture

Hi,

Can you explain a little bit more in detail how to set up this feature I cannot do it. I see no strings for metatag type to translate on admin/config/regional/translate/translate

Thanks!

DamienMcKenna’s picture

@valery86: Please check the main README.txt file for some instructions.

yang_yi_cn’s picture

Note that as of 1.x-beta7, it only works for the overrides in the "Defaults" tab, but if you have Metatag context (by path) then the string in there are not translatable.

That issue is reported at #1986032: i18n support for Metatag submodules (Views, Context, Panels)

gillesbailleux’s picture

Hi,

This is the excerpt about i18n in the README.txt in the 7.x-1.0-beta7 version:

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.

So I went to fr/admin/config/search/metatags/config/global%3Afrontpage, copied the content of the first row (page title), went to fr/admin/config/regional/translate/translate, pasted the page title content and hit enter.

I translated the page title in english and nothing happened until I flushed all caches. So my guess is you could mention to flush caches in the README.txt in order to see the changes take place.

Many thanks to the community for this great achievement as this i18n + metatag issue lasts for quite a while.

Regards,

Gilles

mgifford’s picture

There's another approach described here using tokens:
https://github.com/wet-boew/wet-boew-drupal/issues/940#issuecomment-2067...

mgifford’s picture

Issue summary:View changes

issue summary

kaido24’s picture

Issue summary:View changes

As I see this translate string is rather annoying and not properly working solution. I have been working on different multilingual problems and solutions and the best multilingual UI-s I've see has been done with Variable module. https://drupal.org/project/variable.
Simple example:
I did create a site and added global description and other metadata.
Later SEO guy says its not ok. You should change source language description. Now I got site with 10 languages and after this tiny change I have to add all the descriptions again (if I copied those to some place).
This was really the best possible problem. I wouldn't want to see clients face if he/she will try to change it.

edit Digged into code and I guess this will never work as I expect because module is not built to work this way.

kaido24’s picture

I guess for me the best solution is to write my own module which will provide my front page related variables with variable module translation support and then I can use metatags module token support to get my site to work properly.

An hour later
Just created this simple module.. https://github.com/kaido24/mgl
Sorry about the module name.. No idea what in my mind :D Hope it will help someone or give some inspiration for solutions.