-
- 615 Posts
In modx you can do things in two ways, the complex way, for people with higher scills than I have, and the simple way, which for me is the best (only) way. And that is some of the things that makes modx genius.
So, my problem (question):
My wish is to be able to use namespaces (values) for different languages from Lexicon in snippet-calls in different templates. Example:
In template baseTemplate_eng, or on a page that use my baseTemplate_eng-template, I want to use this call [[SimpleSearch &use_namespace-value_for_the_english_part_(en)_for_this_snippet_in_Lexicon_manager]].
In template baseTemplate_nor, or on a page that use my baseTemplate_nor-template, I want to use this call [[SimpleSearch &use_namespace-value_for_the_norwegian_part_(no)_for_this_snippet_in_Lexicon_manager]].
Is there a way to do this? (Sorry if this is obvious, I couldn't find it by searching the forums, stackoverflow or other places.)
Thanks.
I think, thererfor I am! But what I am, and why...?
-
- 24,544 Posts
You can use full language string tags:
[[%LanguageStringKey?
&language=`en`
&namespace=`NameSpaceName`
&topic=`TopicName`
]]
As an alternative, you can use regular language tags with just the key and create a custom snippet to put in the template that will load the appropriate lexicon:
$modx->lexicon->load('language:namespace:topic');
That will always overwrite the current values with those from the files you specify.
-
- 615 Posts
Quote from: BobRay at Jan 06, 2014, 08:36 AMYou can use full language string tags:
[[%LanguageStringKey?
&language=`en`
&namespace=`NameSpaceName`
&topic=`TopicName`
]]
Thanks! I got that part working alright. What I miss is the simple way of telling a snippet which language I want to use, like this: [[SimpleSearch &lang=`en`]] or [[SimpleSearch &lang=`no`]].
But I don't know if that's possible. I guess it can be done in some way with Contexts, but for me Contexts is unfortunately too complicated, and I just don't need that complexity. Not for this site.
I think, thererfor I am! But what I am, and why...?
-
- 40 Posts
Or, use your lexicon string INSIDE the snippet. I guess, MODX allows it.
-
- 615 Posts
Thanks for answering, but in my case here I don't want to use Contexts. And the language settings should be placed within the snippet-call in the template, not via a TV.
I realize now that this problem can not be solved without using Contexts, or reprogram the SimpleSearch snippet, so I will instead present it as a request in another post:
A new default-function in modx-snippets: use &lang=`` to load the corresponding lang-strings from Lexicon without the use of Context.
I think, thererfor I am! But what I am, and why...?
-
- 24,544 Posts
What I miss is the simple way of telling a snippet which language I want to use, like this: [[SimpleSearch &lang=`en`]] or [[SimpleSearch &lang=`no`]].
How do *you* know what language you want the snippets to use? If it's the URL they come in on, setting a $_SESSION variable would be one way. You could also make it a User Setting (if they're logged in), or a cookie. Many snippets have a &language property, even though it's often undocumented.
-
- 40 Posts
Better to use lexicon calls inside the snippet itself, and pass the language into them with some kind of TV, because, I assume, the snippet is used on two different pages (with different languages)?
-
- 24,544 Posts
Right, but the OP is talking about existing MODX snippets that don't have that capability.
That said, many of those snippets (e.g. getResources) use Tpl chunk and you could put language tags in those chunks.