Attribute Value Localizer
Permalink Browser Info Environment
How do you apply this to a value of an attribute?
So the translation has been filled out, but what do I need to change in the following?
<?php echo $c->getCollectionAttributeValue('region') ?>
Thanks!
So the translation has been filled out, but what do I need to change in the following?
<?php echo $c->getCollectionAttributeValue('region') ?>
Thanks!
Type: | Discussion |
---|---|
Status: | New |
Hi Michele,
thanks, but then it just outputs region, not its values.
Using:
thanks, but then it just outputs region, not its values.
Using:
echo tc('SelectAttributeValue', region);
Actually I just tried the same thing. It will display its value, but not the translated value.
Same effect with:
echo $c->getCollectionAttributeValue(tc('SelectAttributeValue','region'))
There's one test we can do.
Let's say that one of your values is "Europe" in English (but please use one of the values of your select attribute instead of 'Europe').
What do you have with the following code?
Let's say that one of your values is "Europe" in English (but please use one of the values of your select attribute instead of 'Europe').
What do you have with the following code?
echo $c->getCollectionAttributeValue(tc('SelectAttributeValue', 'Europe'));
When I do 'region', it will display its region (in the original attribute language).
But when I do 'Europe' its empty.
But when I do 'Europe' its empty.
Ups, my fault: copy-and-paste problem.
Could you please try this?
Where instead of 'Europe' you should write one of the attributes that you translated with Localizer.
What do you get?
Could you please try this?
echo tc('SelectAttributeValue', 'Europe');
Where instead of 'Europe' you should write one of the attributes that you translated with Localizer.
What do you get?
If I have 'West-Europa' it will stay West-Europe, in any language.
I did off course add the values Europe for German and Europe2 for Dutch in 'Translate special items' of Localizer.
I did off course add the values Europe for German and Europe2 for Dutch in 'Translate special items' of Localizer.
I need to summarize your settings...
You created a custom page attribute of type "select", with the handle "region" and with some values (one of which is 'West-Europe').
After that you used my Localizer to translate this 'West Europe' value (among others) to the German "Westeuropa".
Is this correct?
You created a custom page attribute of type "select", with the handle "region" and with some values (one of which is 'West-Europe').
After that you used my Localizer to translate this 'West Europe' value (among others) to the German "Westeuropa".
Is this correct?
That's correct. In German actually "Europe" for the moment just to notice the difference a bit better :)
In English:
Current locale: en_GB
West-Europe
In German:
Current locale: de_DE
West-Europe
Could it have something do with this? Because in the translation panel in the empty fields it says "Same as English (US)"
So not GB...
Current locale: en_GB
West-Europe
In German:
Current locale: de_DE
West-Europe
Could it have something do with this? Because in the translation panel in the empty fields it says "Same as English (US)"
So not GB...
Basically "Same as English (US)" means "Don't translate", so this is not the problem.
To determine what's going wrong, could you try to modify the file /packages/localizer/controller.php?
In particular, take out these lines:
And replace them with these lines:
You should see one or more red boxes: what do they contain?
To determine what's going wrong, could you try to modify the file /packages/localizer/controller.php?
In particular, take out these lines:
public static function localeLoaded($locale, $allowCache = false) { if($locale != 'en_US') { $filename = Loader::helper('localizer', 'localizer')->getLocalizationFilename($locale); if(is_file($filename)) { $translate = Localization::getInstance()->getActiveTranslateObject(); if($translate) { $translate->addTranslation(array('content' => $filename, 'locale' => $locale, 'reload' => $allowCache ? false : true)); } } } }
And replace them with these lines:
public static function localeLoaded($locale, $allowCache = false) { echo '<div style="color: yellow; background-color: red; border: solid 5px yellow">'; echo 'localeLoaded: ' . $locale . '<br />'; if($locale != 'en_US') { echo 'Not en_US: going on<br />'; $filename = Loader::helper('localizer', 'localizer')->getLocalizationFilename($locale); if(is_file($filename)) { echo 'Localizer translation file found<br />'; $translate = Localization::getInstance()->getActiveTranslateObject(); if($translate) { $translate->addTranslation(array('content' => $filename, 'locale' => $locale, 'reload' => $allowCache ? false : true)); echo 'Localizer translations loaded<br />'; } } }
Viewing 15 lines of 17 lines. View entire code block.
You should see one or more red boxes: what do they contain?
One red box, saying the same in every language: localeLoaded: en_US
That's quite strange.
By keeping the above edit, could you try this?
...what's the output?
By keeping the above edit, could you try this?
echo 'ENABLE_APPLICATION_EVENTS: '; if(defined('ENABLE_APPLICATION_EVENTS')) { echo trim(var_export(ENABLE_APPLICATION_EVENTS, true)); } else { echo 'default'; } echo '<br />'; echo 'Attribute in ' . Localization::activeLocale(); echo '<br />'; echo tc('SelectAttributeValue', 'West Europe'); Localization::changeLocale('de_DE'); echo 'Attribute in ' . Localization::activeLocale(); echo '<br />'; echo tc('SelectAttributeValue', 'West Europe');
...what's the output?
Adding this code to the page I get:
ENABLE_APPLICATION_EVENTS: true
Attribute in de_DE
West-EuropeAttribute in de_DE
West-Europe
the red box remains "localeLoaded: en_US"
Figured out what is happening there. It displays the locale for the backend, which is on US. Do I change this to Duch it gives me:
localeLoaded: nl_NL
Not en_US: going on
Localizer translation file found
Localizer translations loaded
ENABLE_APPLICATION_EVENTS: true
Attribute in de_DE
West-EuropeAttribute in de_DE
West-Europe
the red box remains "localeLoaded: en_US"
Figured out what is happening there. It displays the locale for the backend, which is on US. Do I change this to Duch it gives me:
localeLoaded: nl_NL
Not en_US: going on
Localizer translation file found
Localizer translations loaded
Ok, maybe I got it.
Where are you placing these echo commands?
Where are you placing these echo commands?
I'm placing them inside a frontend theme, in this case a page type called project.php
Sorry for the late response.
The problem is not in Localizer: it's due to the way concrete5 handles localization...
The user's language takes the precedence on the page language...
The problem is not in Localizer: it's due to the way concrete5 handles localization...
The user's language takes the precedence on the page language...
No worries, thanks for helping my anyway!
Isn't there a way to adjust Localizer so it can handle the localization of concrete5?
Instead of connecting it to the users backend language, connect it with the front end visitors selected language?
Isn't there a way to adjust Localizer so it can handle the localization of concrete5?
Instead of connecting it to the users backend language, connect it with the front end visitors selected language?
Sure! You can retrieve the locale of the current page:
// Determine current locale and page locale $currentLocale = Localization::activeLocale(); $pageLocale = $currentLocale; Loader::model('section', 'multilingual'); $ms = MultilingualSection::getCurrentSection(); if (is_object($ms)) { $pageLocale = $ms->getLocale(); if($pageLocale != $currentLocale) { Localization::changeLocale($pageLocale); } } // do your stuff here // Recover previous locale if($pageLocale != $currentLocale) { Localization::changeLocale($currentLocale);
Viewing 15 lines of 16 lines. View entire code block.
Hi - I'm trying to do the same thing - Can you just clarify for me if this is possible or not please? I couldn't quite tell from this thread whether Dutchwave was successful or not.
I have translated all my page attribute values in localizer, and am now trying to echo them out in a page template - whatever I've done so far, I can only get the default language value to show regardless of which locale I'm in.
Thanks!
I have translated all my page attribute values in localizer, and am now trying to echo them out in a page template - whatever I've done so far, I can only get the default language value to show regardless of which locale I'm in.
Thanks!
Just in case anyone stumbles on this and is trying to work it out - the code required is:
- obviously changing 'colour' for your select attribute handle.
echo tc('SelectAttributeValue', $c->getCollectionAttributeValue('colour'));
- obviously changing 'colour' for your select attribute handle.
To localize attributes you should use the 'SelectAttributeValue' context:
Please remark that the global tc function is available from version 5.6.1 of concrete5 (for reference: see the "functions" sections of minehttp://lnx.locati.it/concrete5-versions-tester/... )
Ciao!
Michele