Reviewed & tested by the community
Project:
Token
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Nov 2010 at 02:59 UTC
Updated:
15 Oct 2021 at 09:58 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
vasikesubscribe. good to have the language object "translated" to tokens
Comment #2
colanI'm assuming that this includes tokens for both the content language and the interface language? #233076: Add token for node's language only works for nodes, but these tokens should be available everywhere.
A use case is setting the Dublin Core language metatag to something like this:
<meta name="dcterms.language" content="eng">The setting for that should come from a token. How about these:
...which would come from:
Comment #3
matsbla commentedThese would be very practical!
Comment #4
pobster commentedI gave it a go...
Thanks,
Pobster
Comment #6
pobster commentedHmmm filename fail - good job anyway as I used language instead of language_content for the replacement...
Thanks,
Pobster
Comment #8
pobster commentedUmmm on Linux, using git... Tried cleaning the line endings manually - this suggests the token.tokens.inc file has bad line endings (I use preserve).
Thanks,
Pobster
Comment #10
pobster commentedOkay I give up, I haven't got time to mess around with this right now. I'll do it later from home, it's hardly a massive change anyway - maybe I'll add to the simpletests as well.
Pobster
Comment #11
pobster commentedFixed typo.
Pobster
Comment #12
mareks commentedI think that the last patch works. I was actually surprised that Token did not have Current UI language before :)
Comment #13
rondev commentedI tested it with https://drupal.org/project/metatag
Seems OK.
I use [language:language-content] for content language in the Global section of Metatag.
Comment #14
damienmckennaOut of interest, would it be worth adding another token to list all of the supported languages for the site?
Comment #15
pobster commentedI believe it does that if you just choose the parent (can't actually remember, it's been a while since I did this).
Thanks,
Pobster
Comment #16
lpalgarvio commentedworks great!
please commit
Comment #17
liquidcms commentedcan anyone give a hint as to what the actual token would be for this?
i am trying to use Display Suite to create a custom field and when i open the token browser to display aprox 200M of tokens, the only one i can find related to language is [node:language] and this only gives the lang code.
Comment #18
liquidcms commentednope, my bad.. i didn't read close enough and assumed 4 yrs into D7 this had been committed.. so applied patch and now i see the tokens in the token browser; but [language-content:name] does not output anything.
Comment #19
liquidcms commentedfor anyone else looking for a solution for this, since the above patch didnt work, i just wrote my own token:
Comment #20
pobster commentedOdd, I tested the patch today and it applied fine for me?
Comment #21
liquidcms commentedpatch applied fine.. but outputs nothing. possibly since you have it declared as type = language; does this mean it won't be usable in a node context? i have mine as type 'node' so it shows within node context; perhaps it should be global though?
Comment #23
Anonymous (not verified) commentedApplied patch to 7.x-1.6 today and both UI language and content language worked just fine.
Would be great to get this committed.
My use case was pre-defining a language facet to a currently active language when going to search-page from a menu item.
Like this:
http://www.example.com/EN/search-all/lang-facet/EN
Now search results are pre-defined to users current language and he/she is still able to extend the search to other languages from facet if needed.
Comment #24
Noe_ commentedJust tried it and it works flawlessly.
Comment #26
jelle_sPatch still applies and works like a charm. I can't see any downsides to it, or any reason why this shouldn't be added. It would be great if this got committed!
Comment #27
damienmckennaBump to see if Dave Reid might be able to provide some insight on what blockers, if any, exist to getting this committed.
Comment #28
pobster commentedWell I'm just glad that people are finding it useful, that's great! :o)
Thanks,
Pobster
Comment #29
mariano.barcia commented+1 to get this committed.
I'm using this patch in PROD.
Thanks very much in advance.
Comment #30
phKU commentedSite wide language code by module implementation, forked from liquidcms, thanks!
Caution: this is D8 version. For D7, please change '\Drupal::languageManager()->getCurrentLanguage()->getId()' to 'i18n_get_lang()'
Comment #31
marassa commentedNot sure the current language token(s) belong in the "site:" section. The "site:" token group includes stuff which is invariant across the whole site but current language isn't. The current language is not site-specific, it's page-specific. With a multilingual web site (probably the only use case where these tokens are even needed in the first place), pages can be rendered in different languages and every instance of a rendered page can only have one currentLanguage.
I vote for
[current-page:language:code]
and
[current-page:language:name]
Comment #32
james.williamsI appreciate that this ticket is already set to RTBC, so feel free to ignore this. But I had a need for a token for the path prefix, since my prefixes don't match my language codes. So here's a patch that adds them, plus tokens for language domains.
@ndlarge @phKU - the D7 patch declares a new token type for languages, so the tokens aren't under 'site' or 'current-page' anyway. That's probably better for any D8 implementation too.
Comment #33
markdc#32 is working fine for me. Thanks.
Comment #34
damienmckennaComment #35
damienmckennaFYI there's a similar issue for D8: #2863200: Current interface language token (D8)
Comment #36
damienmckennaFYI I put together an initial patch for D8 in #2863200: Current interface language token (D8).
Comment #37
alfthecat commentedPatch of #32 applies cleanly, but I don't have a token for the language a user account is in....
Comment #38
pobster commented"language-ui" will provide you with this ~ the UI will be in the active users language.
Comment #39
alfthecat commented@pobster, thanks. But doesn't that provide the ui language of the user that's currently logged in?
In my case I really need the token for the language of each individual account (for bulk operations and syncing of data to 3rd party apps). I figure the language-ui would return the interface language of the site admin who's performing the (bulk) operation...
Comment #40
damienmckenna@AlfTheCat: Please open a new feature request for that.
Comment #41
alfthecat commented@DamienMcKenna,
Thanks! Just created a new issue. #2973058: Create a 'user:language' token type (D7)
Comment #42
papagrandeThis patch saved my bacon for a views argument on an entity reference field. Thanks! RTBC!
Comment #43
giupenni commentedThis patch saved my day. Works like a charm!
Comment #44
anybodyAny further plans here? #2863200: Current interface language token (D8) is Fixed and this is RTBC.
Comment #45
philyPatch #32 is still working for me using Drupal 7.82 & Token 7.x-1.8
Thanks