getkirby-v2 / toolkit

This is the deprecated toolkit for Kirby v2.
http://getkirby.com
81 stars 50 forks source link

$locale param in l::get() function needs to be removed #278

Closed minimalweb closed 3 years ago

minimalweb commented 6 years ago

If for example, I have set up two languages and want to do something like this:

German Salutation: <?php echo l::get('salutation', null, 'de_DE') ?><br>
English Salutation: <?php echo l::get('salutation', null, 'en_US') ?>

Both would output the same string, based on the current site locale and not based on the locale you have provided as an argument.

lukasbestle commented 6 years ago

The third $locale param was actually for a different feature, which has been removed (apparently we forgot to remove the third param, which isn't used by the method anymore).

The feature was never intended to get a variable from a different language. That's actually not possible as Kirby only loads the locale file of the current language. What is your use-case where you need the variable in a different language?

minimalweb commented 6 years ago

People can subscribe to a newsletter and pick one or two languages (or both) in which they want to receive it. For both languages, a salutation will be sent to the newsletter service. So regardless, of the language the website is viewed in at that moment, I need to get the salutation for both languages.

texnixe commented 6 years ago

But the rest of the newsletter in the two languages is handled by the newsletter service? If so, you might as well handle the salutation there as well?

If you really need the salutation in both languages from Kirby, instead of using the language variables, you can use set an array in your config.

c::set('lang-variables', [
  'salutation' => [
    'en' => 'Hi',
    'de' => 'Hallo'
  ]
]);
$variables = c::get('lang-variables');
$germanSalutation = $variables['salutation']['de'];
$englishSalutation = $variables['salutation']['en'];
lukasbestle commented 6 years ago

Just wanted to write the same as @texnixe. :)

I'm leaving this issue open because of the documentation issue, but if you have any further questions about your use-case, please ask in the forum.

minimalweb commented 6 years ago

Thanks for the quick replies. Unfortunately, the newsletter service cannot handle the salutation in an intelligent way, so I will use the config settings.