Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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)
Comment | File | Size | Author |
---|---|---|---|
#82 | metatag-n1282620-82.patch | 5.05 KB | DamienMcKenna |
#80 | metatag-multilingual-support-1282620-68-rev1.patch | 4.57 KB | zterry95 |
#77 | metatag-n1282620-77.patch | 4.67 KB | DamienMcKenna |
#68 | metatag-multilingual-support-1282620-68.patch | 5.15 KB | Peacog |
#63 | multilingual_metatag-1282620-63.patch | 4.55 KB | Lukas von Blarer |
Comments
Comment #1
tsvenson CreditAttribution: tsvenson commentedPlease 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.
Comment #2
tsvenson CreditAttribution: tsvenson commentedComment #3
jherencia CreditAttribution: jherencia commentedYes, 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.
Comment #4
idflood CreditAttribution: idflood commentedI 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.
Comment #5
mgiffordSubscribe. And ya, hopefully it's just a matter of the global & global: homepage tags.
Comment #6
datarazor CreditAttribution: datarazor commentedEssential, subscribing.
keywords: localization, language, translation.
Comment #7
mgiffordTagging @datarazor's keywords.
Comment #8
tty11Subscribe.
For information, no multitlingual support it's a mater for multilingual taxonomy term.
Comment #9
dimon00 CreditAttribution: dimon00 commentedOne 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).
Comment #10
maxxer CreditAttribution: maxxer commentedbump! my understanding is this module is completely incompatible with entity translate....
Comment #11
renat CreditAttribution: renat commentedLooks 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.
Comment #12
mgiffordCan you document how this should be done?
Comment #13
maxxer CreditAttribution: maxxer commentedApologies 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.
Note we have to define $lang and $node in template.php
Comment #14
Dave ReidIt 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.
Comment #15
idflood CreditAttribution: idflood commentedThe 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.
Comment #16
mgiffordThe concerns are primarily with the front page or views, right? Each node should still be able to present node & language specific metatags, right?
Comment #17
idflood CreditAttribution: idflood commentedWith some inspiration from #11 this could be useful in these situations:
- global
- front page
- panels
- nodes with entity-based translations
Comment #18
epawel CreditAttribution: epawel commentedIs there any chance to set different descriptions or keywords depending on domain ? Any help would be very appreciated
Comment #19
idflood CreditAttribution: idflood commented#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
Comment #20
Kristen Pol@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
Comment #21
idflood CreditAttribution: idflood commented@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.
But the patch does nothing right know. Some piece of code are still missing to make it working.
Comment #22
Kristen PolAh... 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
Comment #23
7thkey CreditAttribution: 7thkey commentedSubscribing.
Comment #24
Danny EnglanderMy 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.
Comment #25
evanbarter CreditAttribution: evanbarter commentedThis 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.
Comment #26
mgiffordI want the bot to test this. Thanks @evanbarter & @idflood for your patches!
Comment #28
idflood CreditAttribution: idflood commentedWow, @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).
Comment #30
Danny EnglanderI 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).
/admin/config/regional/translate/i18n_string
, see the new checkbox for "Metatag" and refreshed the strings for that./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...Comment #31
idflood CreditAttribution: idflood commented#28: multilingual_metatag-1282620-28.patch queued for re-testing.
Comment #33
idflood CreditAttribution: idflood commented@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.
Comment #34
kemo1 CreditAttribution: kemo1 commentedSubscribing.
Comment #35
rooby CreditAttribution: rooby commentedNot 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.
Comment #36
rooby CreditAttribution: rooby commentedAlso note that xml:lang is the preferred attribute but both xml:lang and lang can be used at the same time if desired.
Comment #37
mgifford#28: multilingual_metatag-1282620-28.patch queued for re-testing.
Comment #39
Kristen PolComment #40
marcoka CreditAttribution: marcoka commentedcan anyone acces the patches? i can click the url but noting happens.
Comment #41
rooby CreditAttribution: rooby commentedThe patch is in comment #28 above, just get it from there.
Comment #42
marcoka CreditAttribution: marcoka commentedok, 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
Comment #43
mgifford#28: multilingual_metatag-1282620-28.patch queued for re-testing.
Comment #45
marcoka CreditAttribution: marcoka commentedhm. retest, just patch formatting change
ignore this patch
stop retesting, wont work, read the test log
Comment #46
mgiffordSorry, 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?
Comment #47
marcoka CreditAttribution: marcoka commentedthe 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.
Comment #48
colanI just created #1688286: Add Entity Translation support to Meta Tags.
Comment #49
colanUpdating title.
Comment #50
josebc CreditAttribution: josebc commentedsubscribe
Comment #51
mgiffordtrying to re-role #28 to see if we can make the bot happier.
Comment #53
idflood CreditAttribution: idflood commentedLet'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.Comment #55
guysaban CreditAttribution: guysaban commentedFor those who need Entity support for Metatag see: http://drupal.org/node/1688286
Comment #56
DamienMcKennaThis needs to work in 1.0.
Comment #57
DamienMcKennaThis needs work:
Comment #58
DamienMcKennaAlso, did the last patch forget to include the metatag.i18n.inc file from earlier patches?
Comment #59
DamienMcKennaFYI #1688286: Add Entity Translation support to Meta Tags has been committed.
Comment #60
Lukas von BlarerIs this issue fixed in this case?
Comment #61
DamienMcKenna@Lukas: no, the non-entity meta tags need work.
Comment #62
Lukas von BlarerObviously it's not... I am re-rolling this patch.
Comment #63
Lukas von BlarerI 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.
I removed variable as a dependency.
The $name varible is used a few lines below.
The metatag_tt() function is still not documented.
Comment #64
Lukas von BlarerWhat has to be done to fix this?
Comment #65
Kristen PolDoes the patch in #63 work for anyone?
Comment #66
mlmsoftwarefactory CreditAttribution: mlmsoftwarefactory commentedMultilingual meta tag for a single page is not possible but can we expand meta tag same in multilingual.
Is it possible?
Comment #67
Kristen Pol@mlmsoftwarefactory I don't understand what you mean... can you give examples of the 2 different options?
Comment #68
Peacog CreditAttribution: Peacog commentedOk, 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.
Comment #69
plachComment #70
DamienMcKennaIs there a reason to define the $name variable in the classes in metatag.inc? The variables aren't actually used.
Comment #71
DamienMcKennaClosed #1883312: Integration with i18n for per-language defaults as a duplicate.
Comment #72
DamienMcKennaMarked #1695040: multilingual support? How to translate meta tags? as a duplicate.
Comment #73
valery86 CreditAttribution: valery86 commentedWill this patch be included in the next Metatags version? If so, when is the next version planned to be released?
Thanks!
Comment #74
DamienMcKenna@valery86: Please see #1860408: Release 7.x-1.0-beta5.
Comment #75
DamienMcKennaMarked #1947100: Meta Tags + i18n as a duplicate.
Comment #76
zterry95 CreditAttribution: zterry95 commentedtest patch of #68, works well for me.
Hope this can be embed into metatag core.
Comment #77
DamienMcKennaRerolled, and removed some unused $name variables.
Comment #78
DamienMcKennaI'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?
Comment #79
DamienMcKennaI can't get this to do anything, some assistance would be appreciated :)
Comment #80
zterry95 CreditAttribution: zterry95 commentedHere 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.
Comment #81
DamienMcKenna@zterry95: Did you forget to include the metatag.i18n.inc file in your patch?
Comment #82
DamienMcKennaThe patch from #80 with the metatag.i18n.inc file from #77.
Comment #83
DamienMcKennaSo 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.
Comment #84
zterry95 CreditAttribution: zterry95 commentedJust 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.
Comment #85
DamienMcKennaIf someone else would care to review the patch in #82 I'll be more than happy to add it to the next beta.
Comment #86
DamienMcKennaCommitted! 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.
Comment #87
zterry95 CreditAttribution: zterry95 commentedcheers!
Comment #88
DamienMcKenna1.0-beta6 is out, so I'm closing this issue in the interest of keeping the issue queue clean.
Comment #89
valery86 CreditAttribution: valery86 commentedHi,
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!
Comment #90
DamienMcKenna@valery86: Please check the main README.txt file for some instructions.
Comment #91
yang_yi_cn CreditAttribution: yang_yi_cn commentedNote 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)
Comment #92
gillesbailleuxHi,
This is the excerpt about i18n in the README.txt in the 7.x-1.0-beta7 version:
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
Comment #93
mgiffordThere's another approach described here using tokens:
https://github.com/wet-boew/wet-boew-drupal/issues/940#issuecomment-2067...
Comment #93.0
mgiffordissue summary
Comment #94
kaido.toomingas CreditAttribution: kaido.toomingas commentedAs 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.
Comment #95
kaido.toomingas CreditAttribution: kaido.toomingas commentedI 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.
Comment #96
kelutrab11 CreditAttribution: kelutrab11 commented@kaido24 kudos! This is working very well. I would like this to be implemented in module.
EDIT: After updating DA and i18n to latest versions I have discovered that Description and Key Words are working properly only for ONE domain/subdomain (but correctly for every enabled language - different text exist in english and different in polish for example). But if you click on SECOND domain and edit them, this will be a new default for ALL domains/subdomains (they will replace the text you put in first domain).
So this module need to recognize variables per domain not only per language. Also it would be nice to put rest of the variables - for example maintenance message, in to the site configuration.
related - https://www.drupal.org/node/2535486