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!

Type: Discussion
Status: New
Dutchwave
View Replies:
mlocati replied on at Permalink Reply
mlocati
Hi Kristian!

To localize attributes you should use the 'SelectAttributeValue' context:
echo tc('SelectAttributeValue', <value of your select attribute>);


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
Dutchwave replied on at Permalink Reply
Dutchwave
Hi Michele,

thanks, but then it just outputs region, not its values.
Using:
echo tc('SelectAttributeValue', region);
mlocati replied on at Permalink Reply
mlocati
What about this?

echo tc('SelectAttributeValue', $c->getCollectionAttributeValue('region'));
Dutchwave replied on at Permalink Reply
Dutchwave
Actually I just tried the same thing. It will display its value, but not the translated value.
Dutchwave replied on at Permalink Reply
Dutchwave
Same effect with:
echo $c->getCollectionAttributeValue(tc('SelectAttributeValue','region'))
mlocati replied on at Permalink Reply
mlocati
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?
echo $c->getCollectionAttributeValue(tc('SelectAttributeValue', 'Europe'));
Dutchwave replied on at Permalink Reply
Dutchwave
When I do 'region', it will display its region (in the original attribute language).
But when I do 'Europe' its empty.
mlocati replied on at Permalink Reply
mlocati
Ups, my fault: copy-and-paste problem.

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?
Dutchwave replied on at Permalink Reply
Dutchwave
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.
mlocati replied on at Permalink Reply
mlocati
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?
Dutchwave replied on at Permalink Reply
Dutchwave
That's correct. In German actually "Europe" for the moment just to notice the difference a bit better :)
mlocati replied on at Permalink Reply
mlocati
Ok, just for a test, what do you get as an output of
echo 'Current locale: ' . Localization::activeLocale();
echo '<br />';
echo tc('SelectAttributeValue', 'West Europe');
Dutchwave replied on at Permalink Reply
Dutchwave
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...
mlocati replied on at Permalink Reply
mlocati
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:
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 />';
         }
      }
   }


You should see one or more red boxes: what do they contain?
Dutchwave replied on at Permalink Reply
Dutchwave
One red box, saying the same in every language: localeLoaded: en_US
mlocati replied on at Permalink Reply
mlocati
That's quite strange.

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?
Dutchwave replied on at Permalink Reply
Dutchwave
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
mlocati replied on at Permalink Reply
mlocati
Ok, maybe I got it.

Where are you placing these echo commands?
Dutchwave replied on at Permalink Reply
Dutchwave
I'm placing them inside a frontend theme, in this case a page type called project.php
mlocati replied on at Permalink Reply
mlocati
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...
Dutchwave replied on at Permalink Reply
Dutchwave
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?
mlocati replied on at Permalink Reply
mlocati
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);
drbiskit replied on at Permalink Reply
drbiskit
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!
drbiskit replied on at Permalink Reply
drbiskit
Just in case anyone stumbles on this and is trying to work it out - the code required is:
echo tc('SelectAttributeValue', $c->getCollectionAttributeValue('colour'));


- obviously changing 'colour' for your select attribute handle.

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.