Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose functions like twigL to PHP side of things #46

Open
xiaohutai opened this issue Jul 13, 2017 · 0 comments
Open

Expose functions like twigL to PHP side of things #46

xiaohutai opened this issue Jul 13, 2017 · 0 comments

Comments

@xiaohutai
Copy link
Contributor

Move twigL functions into a separate Service class and inject it as app['labels.service'] (or add the functions to the app['labels'] class), then have helper functions exposed:

  • translate($label, $lang = false) exposed for other extensions to use.
  • setCurrentLanguage
  • etc.

Currently, I'm doing the following in my extension:

$labels = $app['labels']->getLabels();
$lang   = mb_strtolower($request->query->get('_locale', 'nl'));
$label  = $app['labels']->cleanLabel('MUH LABEL');
$result = $label;

if (isset($labels[$label][$lang]) && !empty($labels[$label][$lang])) {
    $result = $labels[$label][$lang];
}
elseif ($app['labels.config']->isAddMissing() && empty($labels[$label])) {
    $app['labels']->addLabel($label);
}

// replace 'MUH LABEL' with the string you need to translate
// use $result as the translated label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant