From d68ba36feef58f03164a6f8127a48716241bc714 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Tue, 3 Jan 2017 17:24:28 -0500 Subject: [PATCH 1/9] update LocaleApi and remove old metatdata access in preparation for migration away from ZLanguage and ZLocale. --- CHANGELOG-1.4.md | 2 +- src/docs/Core-2.0/Api/LocaleApi.md | 12 +- .../TranslationAndLanguage/Language.md | 14 -- .../MigrationFromZLanguage.md | 31 +++ src/lib/bootstrap.php | 3 + .../RoutesModule/Twig/TwigExtension.php | 2 +- src/system/SettingsModule/Api/LocaleApi.php | 212 +++--------------- .../Listener/LocaleListener.php | 63 ------ .../Resources/config/services.yml | 7 - 9 files changed, 73 insertions(+), 273 deletions(-) delete mode 100644 src/docs/Core-2.0/TranslationAndLanguage/Language.md create mode 100644 src/docs/Core-2.0/TranslationAndLanguage/MigrationFromZLanguage.md delete mode 100644 src/system/SettingsModule/Listener/LocaleListener.php diff --git a/CHANGELOG-1.4.md b/CHANGELOG-1.4.md index 4ef4faf28f..b58db873e1 100644 --- a/CHANGELOG-1.4.md +++ b/CHANGELOG-1.4.md @@ -4,7 +4,7 @@ CHANGELOG - ZIKULA 1.4.x * 1.4.6 (?) - BC Breaks: - - ? + - LocaleApi (introduced in 1.4.4) has been refactored and eliminates access to locale metadata. - Deprecated: - \StreamReader_* diff --git a/src/docs/Core-2.0/Api/LocaleApi.md b/src/docs/Core-2.0/Api/LocaleApi.md index a0742b6c20..a5a437178e 100644 --- a/src/docs/Core-2.0/Api/LocaleApi.md +++ b/src/docs/Core-2.0/Api/LocaleApi.md @@ -5,15 +5,9 @@ classname: \Zikula\SettingsModule\Api\LocaleApi service id="zikula_settings_module.locale_api" -This class loads the definitions associated with a locale and allows the developer to fetch the properties of that -locale with e.g. `$localeApi->language_direction` or `$localeApi->currency_symbol`. The data is read from the locale's -`.ini` file which is located in `/app/Resources/locale//locale.ini`. - -The class is available as a Twig global variable as `localeApi` e.g. `{{ localeApi.language_direction }}`. - -The class is loaded via an onRequest listener: `\Zikula\SettingsModule\Listener\LocaleListener` +This class defines the locales that are supported based on the translations available in `app/Resources/translations`. The class makes the following methods available: - - load($locale, $rootDir) - - __call($key, $args) + - getSupportedLocales() + - getSupportedLocaleNames() diff --git a/src/docs/Core-2.0/TranslationAndLanguage/Language.md b/src/docs/Core-2.0/TranslationAndLanguage/Language.md deleted file mode 100644 index 9b820759eb..0000000000 --- a/src/docs/Core-2.0/TranslationAndLanguage/Language.md +++ /dev/null @@ -1,14 +0,0 @@ -notes: ------- - -ZLanguage::getLanguageCode() is replaced by $request->getLocale() - -ZLanguage::getEncoding() is replaced by ZikulaKernel->getCharset() // default 'UTF-8' - -zikula_settings_module.locale_api provides access to locale metadata -@see \Zikula\SettingsModule\Api\LocaleApi - -twig global variable `localeApi` gives access to locale_api for example: - - - diff --git a/src/docs/Core-2.0/TranslationAndLanguage/MigrationFromZLanguage.md b/src/docs/Core-2.0/TranslationAndLanguage/MigrationFromZLanguage.md new file mode 100644 index 0000000000..c522f08bd9 --- /dev/null +++ b/src/docs/Core-2.0/TranslationAndLanguage/MigrationFromZLanguage.md @@ -0,0 +1,31 @@ +Replacing ZLanguage +=================== + +In the examples below, the provided variable (e.g. $container, $kernel, etc) must be adjusted to match the environment +from which it may be obtained. These variables are not defined explicitly in most cases. + + +ZLanguage::getLanguageCode() becomes $container->getParameter('locale') + +ZLanguage::getModuleDomain('AcmeFooModule') becomes $kernel->getModule('AcmeFooModule')->getTranslationDomain() + +ZLanguage::getDirection() becomes use `dir=auto` in the template instead + +ZLanguage::getLanguageName($code) becomes \Intl::getLanguageBundle()->getLanguageName($locale) + +ZLanguage::getInstalledLanguages() becomes $localeApi->getSupportedLocales() + +ZLanguage::getInstalledLanguageNames() becomes $localeApi->getSupportedLocaleNames() + +ZLanguage::setLocale('en') becomes depends on the need. probably set in the Request $request->setLocale('en') + maybe need to set the parameter in the container or in config.yml (or both) + +ZLanguage::getLocale() becomes $request->getLocale() + +ZLanguage::bind*Domain('AcmeFooModule') becomes no longer needed with symfony translator + +ZLanguage::getEncoding() becomes $kernel->getCharset() + +ZLanguage::isRequiredLangParam() is handled automatically by the router + +ZLanguage::countryMap() becomes \Intl::getRegionBundle()->getCountryNames() diff --git a/src/lib/bootstrap.php b/src/lib/bootstrap.php index e2ef965dec..0cf8aae77b 100644 --- a/src/lib/bootstrap.php +++ b/src/lib/bootstrap.php @@ -29,6 +29,9 @@ umask($kernelConfig['umask']); } +// set default locale for Intl classes +\Locale::setDefault($kernelConfig['locale']); + // on install or upgrade, check if system requirements are met. requirementCheck($kernelConfig); diff --git a/src/system/RoutesModule/Twig/TwigExtension.php b/src/system/RoutesModule/Twig/TwigExtension.php index ac6c26edcd..e81cc075cc 100644 --- a/src/system/RoutesModule/Twig/TwigExtension.php +++ b/src/system/RoutesModule/Twig/TwigExtension.php @@ -102,7 +102,7 @@ public function displayPathAsString($path, $route) $path = preg_replace_callback('#{(.*?)}#', function ($matches) use ($container, $defaults, $requirements) { $title = ''; if (isset($defaults[$matches[1]])) { - $title .= $this->translator->__f('Default: %s', ['%s' => DataUtil::formatForDisplay($defaults[$matches[1]])]); + $title .= $this->__f('Default: %s', ['%s' => DataUtil::formatForDisplay($defaults[$matches[1]])]); } if (isset($requirements[$matches[1]])) { if ($title != '') { diff --git a/src/system/SettingsModule/Api/LocaleApi.php b/src/system/SettingsModule/Api/LocaleApi.php index a094f78343..9bac029fa9 100644 --- a/src/system/SettingsModule/Api/LocaleApi.php +++ b/src/system/SettingsModule/Api/LocaleApi.php @@ -11,201 +11,57 @@ namespace Zikula\SettingsModule\Api; -use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; -use Symfony\Component\Filesystem\Filesystem; +use Symfony\Component\Finder\Finder; +use Symfony\Component\Intl\Intl; class LocaleApi { /** - * @var bool has locale been loaded? + * Locales with translations present + * @var array */ - private $loaded = false; + private $supportedLocales = []; /** - * @var string local name - */ - private $locale = 'en'; - - /** - * @var string ltr or rtl for left or right - */ - private $language_direction = 'ltr'; - - /** - * @var string decimal point character - */ - private $decimal_point = '.'; - - /** - * @var string thousands separator - */ - private $thousands_sep = ','; - - /** - * @var string international currency symbol (i.e. EUR) - */ - private $int_curr_symbol = 'EUR'; - - /** - * @var string local currency symbol (i.e. €) - */ - private $currency_symbol = '€'; - - /** - * @var string monetary decimal point character - */ - private $mon_decimal_point = '.'; - - /** - * @var string monetary thousands separator - */ - private $mon_thousands_sep = ','; - - /** - * @var string sign for positive values - */ - private $positive_sign = ''; - - /** - * @var string sign for negative values - */ - private $negative_sign = '-'; - - /** - * @var int international fractional digits - */ - private $int_frac_digits = 2; - - /** - * @var int local fractional digits - */ - private $frac_digits = 2; - - /** - * @var bool TRUE if currency_symbol precedes a positive value, FALSE if it succeeds one - */ - private $p_cs_precedes = true; - - /** - * @var bool TRUE if a space separates currency_symbol from a positive value, FALSE otherwise - */ - private $p_sep_by_space = true; - - /** - * @var bool TRUE if currency_symbol precedes a negative value, FALSE if it succeeds one - */ - private $n_cs_precedes = true; - - /** - * @var bool TRUE if a space separates currency_symbol from a negative value, FALSE otherwise - */ - private $n_sep_by_space = true; - - /** - * @var int - * 0 - parentheses surround the quantity and currency_symbol - * 1 - The sign string precedes the quantity and currency_symbol - * 2 - The sign string succeeds the quantity and currency_symbol - * 3 - The sign string immediately precedes the currency_symbol - * 4 - The sign string immediately succeeds the currency_symbol - */ - private $p_sign_posn = 1; - - /** - * @var int - * 0 - parentheses surround the quantity and currency_symbol - * 1 - The sign string precedes the quantity and currency_symbol - * 2 - The sign string succeeds the quantity and currency_symbol - * 3 - The sign string immediately precedes the currency_symbol - * 4 - The sign string immediately succeeds the currency_symbol - */ - private $n_sign_posn = 2; - - /** - * @var int 0 = Sunday, 1 Monday etc - */ - private $firstweekday = 0; - - /** - * @var string Use 12/24 depending on country - */ - private $timeformat = '24'; - - /** - * @var array An array containing numeric groupings - */ - private $grouping = []; - - /** - * @var array An array containing monetary groupings - */ - private $mon_grouping = []; - - /** - * @see \Zikula\SettingsModule\Listener\LocaleListener - * @param $locale - * @param $rootDir - */ - public function load($locale, $rootDir) - { - if ($this->loaded) { - return; - } - $this->locale = $locale; - $fs = new Filesystem(); - $path = $rootDir . '/Resources/locale/' . $this->locale . '/locale.ini'; - if ($fs->exists($path)) { - $this->parseIniFile($path); - } else { - throw new InvalidConfigurationException('Could not load the locale configuration.'); - } - $this->loaded = true; - } - - /** - * Allows Twig to fetch properties without use of ArrayAccess - * - * ArrayAccess is problematic because Twig uses isset() to - * check if property field exists, so it's not possible - * to get using default values, ie, empty. + * Get array of supported locales * - * @param $key - * @param $args - * - * @return string + * @return array */ - public function __call($key, $args) + public function getSupportedLocales() { - if (!$this->loaded) { - throw new InvalidConfigurationException('Did not load the locale configuration.'); + if (empty($this->supportedLocales)) { + $this->supportedLocales[] = 'en'; + $finder = new Finder(); + $files = $finder->files() + ->in(['app/Resources/translations']) + ->depth(0) + ->name('*.po') + ->notName('*.template.*'); + foreach ($files as $file) { + $fileName = $file->getBasename('.po'); + list($domain, $locale) = explode('.', $fileName); + if (!in_array($locale, $this->supportedLocales)) { + $this->supportedLocales[] = $locale; + } + } } - return $this->$key; + return $this->supportedLocales; } /** - * Parse an .ini file and set the object properties based on their current type. - * @param $path + * Get array of supported locales with their translated name + * + * @return array */ - private function parseIniFile($path) + public function getSupportedLocaleNames() { - $iniFile = parse_ini_file($path, false); - foreach ($iniFile as $key => $data) { - if (property_exists($this, $key)) { - switch (true) { - case is_bool($this->$key): - $this->$key = (bool) $data; - break; - case is_array($this->$key): - $this->$key = explode(',', $data); - break; - case is_int($this->$key): - $this->$key = (int) $data; - break; - default: - $this->$key = $data; - } - } + $locales = $this->getSupportedLocales(); + $namedLocales = []; + foreach ($locales as $locale) { + $namedLocales[Intl::getLanguageBundle()->getLanguageName($locale)] = $locale; } + + return $namedLocales; } } diff --git a/src/system/SettingsModule/Listener/LocaleListener.php b/src/system/SettingsModule/Listener/LocaleListener.php deleted file mode 100644 index 7b402acc27..0000000000 --- a/src/system/SettingsModule/Listener/LocaleListener.php +++ /dev/null @@ -1,63 +0,0 @@ -kernel = $kernel; - $this->localeApi = $localeApi; - } - - public function onKernelRequest(GetResponseEvent $event) - { - if (!$event->isMasterRequest()) { - return; - } - $locale = $event->getRequest()->getLocale(); - if (!isset($locale)) { - $locale = $event->getRequest()->getDefaultLocale(); - } - $this->localeApi->load($locale, $this->kernel->getRootDir()); - } - - public static function getSubscribedEvents() - { - return [ - KernelEvents::REQUEST => [ - ['onKernelRequest', 202] - ] - ]; - } -} diff --git a/src/system/SettingsModule/Resources/config/services.yml b/src/system/SettingsModule/Resources/config/services.yml index 21dd02a80e..6875688d2d 100644 --- a/src/system/SettingsModule/Resources/config/services.yml +++ b/src/system/SettingsModule/Resources/config/services.yml @@ -2,7 +2,6 @@ parameters: zikula_settings_module.container.link_container.class: Zikula\SettingsModule\Container\LinkContainer zikula_settings_module.module_listener.class: Zikula\SettingsModule\Listener\ModuleListener zikula_settings_module.locale_api.class: Zikula\SettingsModule\Api\LocaleApi - zikula_settings_module.listener.locale_listener.class: Zikula\SettingsModule\Listener\LocaleListener zikula_settings_module.listener.localized_variable_listener.class: Zikula\SettingsModule\Listener\LocalizedVariableListener services: @@ -25,12 +24,6 @@ services: zikula_settings_module.locale_api: class: "%zikula_settings_module.locale_api.class%" - zikula_settings_module.listener.locale_listener: - class: "%zikula_settings_module.listener.locale_listener.class%" - arguments: ["@kernel", "@zikula_settings_module.locale_api"] - tags: - - { name: kernel.event_subscriber } - zikula_settings_module.listener.localized_variable_listener: class: "%zikula_settings_module.listener.localized_variable_listener.class%" arguments: ["@zikula_extensions_module.api.variable"] From 5b747a9ab2d2d138450410fe045b80aa98b45256 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 4 Jan 2017 16:33:02 -0500 Subject: [PATCH 2/9] remove use of LocaleApi and add Intl docs --- src/app/config/config.yml | 2 +- .../Core-2.0/TranslationAndLanguage/Intl.md | 26 +++++++ .../HookBundle/Hook/AbstractHookListener.php | 71 ++++--------------- .../views/includePdfHeader.html.twig | 2 +- .../DefaultPageVarSetterListener.php | 9 --- .../config/theme_engine_event_listeners.yml | 25 ++++++- .../Resources/views/Include/header.html.twig | 2 +- .../Resources/views/Include/header.html.twig | 2 +- 8 files changed, 65 insertions(+), 74 deletions(-) create mode 100644 src/docs/Core-2.0/TranslationAndLanguage/Intl.md diff --git a/src/app/config/config.yml b/src/app/config/config.yml index 95fc21352d..28a3cd4bfb 100644 --- a/src/app/config/config.yml +++ b/src/app/config/config.yml @@ -38,7 +38,7 @@ twig: pagevars: "@zikula_core.common.theme.pagevars" themevars: "@zikula_core.common.theme.themevars" currentUser: "@zikula_users_module.current_user" - localeApi: "@zikula_settings_module.locale_api" + localeApi: { "language_direction": "auto" } # Doctrine Configuration doctrine: diff --git a/src/docs/Core-2.0/TranslationAndLanguage/Intl.md b/src/docs/Core-2.0/TranslationAndLanguage/Intl.md new file mode 100644 index 0000000000..9543440a57 --- /dev/null +++ b/src/docs/Core-2.0/TranslationAndLanguage/Intl.md @@ -0,0 +1,26 @@ +Using the Php & Symfony's Intl classes +====================================== + +Zikula expects php's `intl extension` to be installed to facilitate internationalization functions within the code. + +http://www.php.net/manual/en/book.intl.php + +If it is installed properly in your php build, you can search your `phpinfo` output and you should find something like +`—enable-intl` in the Configure Command and `Internationalization support => enabled` in the output. If these are NOT +found, then polyfill-type solutions are in place from symfony: + +http://symfony.com/doc/current/components/intl.html + +These will enable the functions to work without error, but the functions will only work for the `en` locale. + +Support in enabling this php extension should be obtained through your web provider. This is not something Zikula +can help with. + + +Symfony's `Intl` class is used as a wrapper to access + - Language and Script Names + - Country Names + - Locales + - Currencies + +http://symfony.com/doc/current/components/intl.html#accessing-icu-data diff --git a/src/lib/Zikula/Bundle/HookBundle/Hook/AbstractHookListener.php b/src/lib/Zikula/Bundle/HookBundle/Hook/AbstractHookListener.php index c8cb1c5735..e79578138c 100644 --- a/src/lib/Zikula/Bundle/HookBundle/Hook/AbstractHookListener.php +++ b/src/lib/Zikula/Bundle/HookBundle/Hook/AbstractHookListener.php @@ -13,13 +13,15 @@ use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher as EventDispatcher; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -use Zikula_TranslatableInterface; +use Zikula\Common\Translator\TranslatorTrait; /** * Custom Hook Handler interface. */ -abstract class AbstractHookListener implements Zikula_TranslatableInterface +abstract class AbstractHookListener { + use TranslatorTrait; + /** * Dispatcher instance. * @@ -63,7 +65,16 @@ abstract class AbstractHookListener implements Zikula_TranslatableInterface public function __construct(EventDispatcherInterface $dispatcher) { $this->dispatcher = $dispatcher; + $this->setTranslator($dispatcher->getContainer()->get('translator.default')); $this->setup(); + if (null !== $this->domain) { + $this->translator->setDomain($this->domain); + } + } + + public function setTranslator($translator) + { + $this->translator = $translator; } /** @@ -93,65 +104,9 @@ public function getDispatcher() /** * Post constructor hook. * - * Generally used to set the $domain property. - * * @return void */ public function setup() { } - - /** - * Translate. - * - * @param string $msgid String to be translated - * - * @return string - */ - public function __($msgid) - { - return __($msgid, $this->domain); - } - - /** - * Translate with sprintf(). - * - * @param string $msgid String to be translated - * @param string|array $params Args for sprintf() - * - * @return string - */ - public function __f($msgid, $params) - { - return __f($msgid, $params, $this->domain); - } - - /** - * Translate plural string. - * - * @param string $singular Singular instance - * @param string $plural Plural instance - * @param string $count Object count - * - * @return string Translated string - */ - public function _n($singular, $plural, $count) - { - return _n($singular, $plural, $count, $this->domain); - } - - /** - * Translate plural string with sprintf(). - * - * @param string $sin Singular instance - * @param string $plu Plural instance - * @param string $n Object count - * @param string|array $params Sprintf() arguments - * - * @return string - */ - public function _fn($sin, $plu, $n, $params) - { - return _fn($sin, $plu, $n, $params, $this->domain); - } } diff --git a/src/system/RoutesModule/Resources/views/includePdfHeader.html.twig b/src/system/RoutesModule/Resources/views/includePdfHeader.html.twig index 4abac73aba..f34bf5571e 100644 --- a/src/system/RoutesModule/Resources/views/includePdfHeader.html.twig +++ b/src/system/RoutesModule/Resources/views/includePdfHeader.html.twig @@ -1,5 +1,5 @@ - + {{ pageGetVar('title') }} diff --git a/src/system/ThemeModule/EventListener/DefaultPageVarSetterListener.php b/src/system/ThemeModule/EventListener/DefaultPageVarSetterListener.php index d23717807c..edebe5cbdf 100644 --- a/src/system/ThemeModule/EventListener/DefaultPageVarSetterListener.php +++ b/src/system/ThemeModule/EventListener/DefaultPageVarSetterListener.php @@ -16,7 +16,6 @@ use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Routing\RouterInterface; -use Zikula\SettingsModule\Api\LocaleApi; use Zikula\ThemeModule\Engine\ParameterBag; use Zikula\ExtensionsModule\Api\VariableApi; @@ -47,11 +46,6 @@ class DefaultPageVarSetterListener implements EventSubscriberInterface */ private $kernel; - /** - * @var LocaleApi - */ - private $localeApi; - /** * @var bool */ @@ -62,14 +56,12 @@ public function __construct( RouterInterface $routerInterface, VariableApi $variableApi, KernelInterface $kernel, - LocaleApi $localeApi, $isInstalled ) { $this->pageVars = $pageVars; $this->router = $routerInterface; $this->variableApi = $variableApi; $this->kernel = $kernel; - $this->localeApi = $localeApi; $this->isInstalled = $isInstalled; } @@ -89,7 +81,6 @@ public function setDefaultPageVars(GetResponseEvent $event) // set some defaults $this->pageVars->set('lang', $event->getRequest()->getLocale()); // @deprecated use app.request.locale in the template - $this->pageVars->set('langdirection', $this->localeApi->language_direction()); // @deprecated use localeApi.language_direction in the template $this->pageVars->set('title', $this->variableApi->getSystemVar('defaultpagetitle')); $this->pageVars->set('meta.charset', $this->kernel->getCharset()); $this->pageVars->set('meta.description', $this->variableApi->getSystemVar('defaultmetadescription')); diff --git a/src/system/ThemeModule/Resources/config/theme_engine_event_listeners.yml b/src/system/ThemeModule/Resources/config/theme_engine_event_listeners.yml index 21e3c9524d..e60a5b451c 100644 --- a/src/system/ThemeModule/Resources/config/theme_engine_event_listeners.yml +++ b/src/system/ThemeModule/Resources/config/theme_engine_event_listeners.yml @@ -19,7 +19,13 @@ services: zikula_core.internal.theme.default_page_asset_setter_listener: class: "%zikula_core.internal.theme.default_page_asset_setter_listener.class%" - arguments: ["@zikula_core.common.theme.assets_js", "@zikula_core.common.theme.assets_css", "@router", "@zikula_core.common.theme_engine", "%kernel.root_dir%", "%compat_layer%"] + arguments: + - "@zikula_core.common.theme.assets_js" + - "@zikula_core.common.theme.assets_css" + - "@router" + - "@zikula_core.common.theme_engine" + - "%kernel.root_dir%" + - "%compat_layer%" calls: - [setParameters, ["@service_container"]] tags: @@ -28,7 +34,12 @@ services: zikula_core.internal.theme.default_page_var_setter_listener: class: "%zikula_core.internal.theme.default_page_var_setter_listener.class%" - arguments: ["@zikula_core.common.theme.pagevars", "@router", "@zikula_extensions_module.api.variable", "@kernel", "@zikula_settings_module.locale_api", "%installed%"] + arguments: + - "@zikula_core.common.theme.pagevars" + - "@router" + - "@zikula_extensions_module.api.variable" + - "@kernel" + - "%installed%" tags: - { name: kernel.event_subscriber } #- { name: monolog.logger, channel: request } @@ -55,7 +66,15 @@ services: zikula_core.internal.theme.add_jsconfig_listener: class: "%zikula_core.internal.theme.add_jsconfig_listener.class%" - arguments: ["%installed%", "@zikula_extensions_module.api.variable", "@zikula_users_module.current_user", "@templating.engine.twig", "@zikula_core.common.theme.themevars", "@zikula_core.common.theme.assets_header", "%zikula.session.name%", "%compat_layer%"] + arguments: + - "%installed%" + - "@zikula_extensions_module.api.variable" + - "@zikula_users_module.current_user" + - "@templating.engine.twig" + - "@zikula_core.common.theme.themevars" + - "@zikula_core.common.theme.assets_header" + - "%zikula.session.name%" + - "%compat_layer%" tags: - { name: kernel.event_subscriber } diff --git a/src/themes/Andreas08Theme/Resources/views/Include/header.html.twig b/src/themes/Andreas08Theme/Resources/views/Include/header.html.twig index 46a56c390f..8f24da5ab3 100644 --- a/src/themes/Andreas08Theme/Resources/views/Include/header.html.twig +++ b/src/themes/Andreas08Theme/Resources/views/Include/header.html.twig @@ -1,5 +1,5 @@ - + {{ pagevars.title }} diff --git a/src/themes/BootstrapTheme/Resources/views/Include/header.html.twig b/src/themes/BootstrapTheme/Resources/views/Include/header.html.twig index 18f6eb6c8b..1e9473db0e 100644 --- a/src/themes/BootstrapTheme/Resources/views/Include/header.html.twig +++ b/src/themes/BootstrapTheme/Resources/views/Include/header.html.twig @@ -1,5 +1,5 @@ - + {{ pagevars.title }} From 20f97cea07c0a3a0d14e518f9722054476835587 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 4 Jan 2017 16:48:39 -0500 Subject: [PATCH 3/9] add warning to template if INTL extension is not loaded. --- src/system/SettingsModule/Controller/SettingsController.php | 1 + .../SettingsModule/Resources/views/Settings/locale.html.twig | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/system/SettingsModule/Controller/SettingsController.php b/src/system/SettingsModule/Controller/SettingsController.php index f18711e17a..13605b8227 100644 --- a/src/system/SettingsModule/Controller/SettingsController.php +++ b/src/system/SettingsModule/Controller/SettingsController.php @@ -139,6 +139,7 @@ public function localeAction(Request $request) } return [ + 'intl_installed' => extension_loaded('intl'), 'form' => $form->createView(), ]; } diff --git a/src/system/SettingsModule/Resources/views/Settings/locale.html.twig b/src/system/SettingsModule/Resources/views/Settings/locale.html.twig index b8bd843ec0..d22ba936c1 100644 --- a/src/system/SettingsModule/Resources/views/Settings/locale.html.twig +++ b/src/system/SettingsModule/Resources/views/Settings/locale.html.twig @@ -3,6 +3,11 @@ 'ZikulaFormExtensionBundle:Form:form_div_layout.html.twig' ] %} {{ adminHeader() }} +{% if not intl_installed|default(false) %} +
+ {{ __f('WARNING: The PHP Extension %ext is not loaded. All functions using this will default to %locale. Seek assistance from your provider to install.', {"%ext": "INTL", "%locale": "EN"})|raw }} +
+{% endif %}

From 4cb1ff0346d0ad7db30b0e3c5defd470a54c6394 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 4 Jan 2017 17:14:06 -0500 Subject: [PATCH 4/9] remove usages of ZLanguage::getLanguageCode() --- .../Bundle/CoreBundle/Twig/Extension/CoreExtension.php | 2 ++ .../Bundle/CoreInstallerBundle/Helper/ControllerHelper.php | 2 -- src/system/CategoriesModule/Api/CategoryApi.php | 7 +++---- src/system/SettingsModule/SettingsModuleInstaller.php | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php b/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php index fc80a26358..f64aeb860f 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php +++ b/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php @@ -108,6 +108,7 @@ public function getAssetPath($path) * Available parameters: * - fs: safe for filesystem. * @return string The language + * @deprecated remove at Core-2.0 use app.request.locale */ public function lang($fs = false) { @@ -120,6 +121,7 @@ public function lang($fs = false) * Function to get the language direction * * @return string the language direction + * @deprecated remove at Core-2.0 use dir="auto" */ public function langDirection() { diff --git a/src/lib/Zikula/Bundle/CoreInstallerBundle/Helper/ControllerHelper.php b/src/lib/Zikula/Bundle/CoreInstallerBundle/Helper/ControllerHelper.php index e6ef315bb9..4189590e3a 100644 --- a/src/lib/Zikula/Bundle/CoreInstallerBundle/Helper/ControllerHelper.php +++ b/src/lib/Zikula/Bundle/CoreInstallerBundle/Helper/ControllerHelper.php @@ -28,8 +28,6 @@ class ControllerHelper public function getTemplateGlobals(StageInterface $currentStage) { $globals = [ - 'lang' => \ZLanguage::getLanguageCode(), - 'charset' => \ZLanguage::getEncoding(), 'version' => \ZikulaKernel::VERSION, 'currentstage' => $currentStage->getName() ]; diff --git a/src/system/CategoriesModule/Api/CategoryApi.php b/src/system/CategoriesModule/Api/CategoryApi.php index ca29658b0f..c74130d074 100644 --- a/src/system/CategoriesModule/Api/CategoryApi.php +++ b/src/system/CategoriesModule/Api/CategoryApi.php @@ -121,8 +121,6 @@ public function createCategory($rootPath, $name, $value = null, $displayname = n $description = $name; } - $lang = ZLanguage::getLanguageCode(); - /** @var CategoryEntity $rootCat */ $rootCat = $this->getCategoryByPath($rootPath); if (!$rootCat) { @@ -141,8 +139,9 @@ public function createCategory($rootPath, $name, $value = null, $displayname = n $data = []; $data['parent'] = $this->entityManager->getReference('ZikulaCategoriesModule:CategoryEntity', $rootCat['id']); $data['name'] = $name; - $data['display_name'] = [$lang => $displayname]; - $data['display_desc'] = [$lang => $description]; + $locale = $this->requestStack->getMasterRequest()->getLocale(); + $data['display_name'] = [$locale => $displayname]; + $data['display_desc'] = [$locale => $description]; if ($value) { $data['value'] = $value; } diff --git a/src/system/SettingsModule/SettingsModuleInstaller.php b/src/system/SettingsModule/SettingsModuleInstaller.php index 44181d2dea..28c7e1dc9f 100644 --- a/src/system/SettingsModule/SettingsModuleInstaller.php +++ b/src/system/SettingsModule/SettingsModuleInstaller.php @@ -89,7 +89,7 @@ public function install() //! this is a comma-separated list of special characters to replace in permalinks $this->setSystemVar('permareplace', $this->__('A,A,A,A,A,a,a,a,a,a,O,O,O,O,O,o,o,o,o,o,E,E,E,E,e,e,e,e,C,c,I,I,I,I,i,i,i,i,U,U,U,u,u,u,y,N,n,ss,ae,Ae,oe,Oe,ue,Ue')); - $this->setSystemVar('language', ZLanguage::getLanguageCodeLegacy()); + $this->setSystemVar('language', ZLanguage::getLanguageCodeLegacy()); // @deprecated $locale = $this->container->getParameter('locale'); $this->setSystemVar('locale', $locale); $this->setSystemVar('language_i18n', $locale); From 821bec6c815864c2c943d1a98fac08a9580389f1 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 4 Jan 2017 19:05:41 -0500 Subject: [PATCH 5/9] refactor usages of ZLanguage --- .../Twig/Extension/CoreExtension.php | 3 +- .../InstallUpgradeCheckListener.php | 2 +- .../Form/Type/LocaleType.php | 3 +- .../CoreInstallerBundle/Stage/LocaleStage.php | 4 +- .../Stage/Upgrade/NotUpgradedStage.php | 4 +- .../Form/Type/LocaleType.php | 5 ++- .../Controller/AdminController.php | 3 +- .../Form/Type/AdminViewFilterType.php | 14 ++++--- .../BlocksModule/Form/Type/BlockType.php | 18 +++++++-- .../Resources/config/services.yml | 6 ++- .../CategoriesModule/Api/CategoryApi.php | 29 ++++++++++----- .../Controller/AdminController.php | 2 +- .../Controller/AjaxController.php | 2 +- .../Controller/UserController.php | 2 +- .../Helper/CategoryProcessingHelper.php | 24 +++++++++--- .../Resources/config/services.yml | 12 +++++- .../Helper/BundleSyncHelper.php | 2 +- .../Controller/ConfigController.php | 3 +- .../MailerModule/Form/Type/ConfigType.php | 5 ++- .../Helper/MultilingualRoutingHelper.php | 25 ++++++++++--- .../RoutesModule/Helper/RouteDumperHelper.php | 8 ++-- .../RoutesModule/Resources/config/helpers.yml | 17 ++++++--- src/system/SettingsModule/Api/LocaleApi.php | 37 ++++++++++++++----- .../Controller/SettingsController.php | 4 +- .../Form/Type/LocaleSettingsType.php | 16 ++++---- .../Form/Type/MainSettingsType.php | 2 +- .../Resources/views/Settings/main.html.twig | 8 ++-- .../SettingsModuleInstaller.php | 7 ++-- .../ThemeModule/Helper/BundleSyncHelper.php | 2 +- .../UsersModule/Container/LinkContainer.php | 14 ++++++- .../Controller/AccountController.php | 6 +-- .../UsersModule/Resources/config/services.yml | 9 ++++- 32 files changed, 202 insertions(+), 96 deletions(-) diff --git a/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php b/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php index f64aeb860f..c270c934e5 100644 --- a/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php +++ b/src/lib/Zikula/Bundle/CoreBundle/Twig/Extension/CoreExtension.php @@ -12,6 +12,7 @@ namespace Zikula\Bundle\CoreBundle\Twig\Extension; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Intl\Intl; use Zikula\Bundle\CoreBundle\Twig; use Zikula\Bundle\CoreBundle\Twig\Extension\SimpleFunction\DefaultPathSimpleFunction; use Zikula\Bundle\CoreBundle\Twig\Extension\SimpleFunction\DispatchEventSimpleFunction; @@ -212,7 +213,7 @@ public function arrayUnset($array, $key) */ public function languageName($code) { - return \ZLanguage::getLanguageName($code); + return Intl::getLanguageBundle()->getLanguageName($code); } public function yesNo($string) diff --git a/src/lib/Zikula/Bundle/CoreInstallerBundle/EventListener/InstallUpgradeCheckListener.php b/src/lib/Zikula/Bundle/CoreInstallerBundle/EventListener/InstallUpgradeCheckListener.php index a16433b346..e82ed90659 100644 --- a/src/lib/Zikula/Bundle/CoreInstallerBundle/EventListener/InstallUpgradeCheckListener.php +++ b/src/lib/Zikula/Bundle/CoreInstallerBundle/EventListener/InstallUpgradeCheckListener.php @@ -91,7 +91,7 @@ private function loadLocales() // write locale choice to `config/dynamic/generated.yml` $configDumper = $this->container->get('zikula.dynamic_config_dumper'); $config = $configDumper->getConfiguration('jms_i18n_routing'); - $config['locales'] = \ZLanguage::getInstalledLanguages(); + $config['locales'] = $this->container->get('zikula_settings_module.locale_api')->getSupportedLocales(); if (!in_array($this->container->getParameter('locale'), $config['locales'])) { $this->container->setParameter('locale', $config['locales'][0]); $config['default_locale'] = $config['locales'][0]; diff --git a/src/lib/Zikula/Bundle/CoreInstallerBundle/Form/Type/LocaleType.php b/src/lib/Zikula/Bundle/CoreInstallerBundle/Form/Type/LocaleType.php index e0447b7285..6d6970c4d7 100644 --- a/src/lib/Zikula/Bundle/CoreInstallerBundle/Form/Type/LocaleType.php +++ b/src/lib/Zikula/Bundle/CoreInstallerBundle/Form/Type/LocaleType.php @@ -41,10 +41,9 @@ public function getBlockPrefix() public function configureOptions(OptionsResolver $resolver) { - $installedLangs = \ZLanguage::getInstalledLanguageNames(); // @todo $resolver->setDefaults([ 'csrf_protection' => false, - 'choices' => array_flip($installedLangs), // flip for proper Symfony 3 choices_as_values + 'choices' => ['English' => 'en'], 'choice' => 'en', 'translator' => new IdentityTranslator() // 'csrf_field_name' => '_token', diff --git a/src/lib/Zikula/Bundle/CoreInstallerBundle/Stage/LocaleStage.php b/src/lib/Zikula/Bundle/CoreInstallerBundle/Stage/LocaleStage.php index 4a7677a2bd..bb2144f55d 100644 --- a/src/lib/Zikula/Bundle/CoreInstallerBundle/Stage/LocaleStage.php +++ b/src/lib/Zikula/Bundle/CoreInstallerBundle/Stage/LocaleStage.php @@ -46,7 +46,7 @@ public function __construct(ContainerInterface $container) { $this->container = $container; $this->yamlManager = new YamlDumper($this->container->get('kernel')->getRootDir() .'/config', 'custom_parameters.yml', 'parameters.yml'); - $this->installedLanguages = \ZLanguage::getInstalledLanguages(); + $this->installedLanguages = $container->get('zikula_settings_module.locale_api')->getSupportedLocales(); $detector = new \ZLanguageBrowser($this->installedLanguages); $this->matchedLocale = $detector->discover(); } @@ -64,7 +64,7 @@ public function getFormType() public function getFormOptions() { return [ - 'choices' => \ZLanguage::getInstalledLanguageNames(), + 'choices' => $this->container->get('zikula_settings_module.locale_api')->getSupportedLocaleNames(), 'choice' => $this->matchedLocale, 'translator' => $this->container->get('translator.default') ]; diff --git a/src/lib/Zikula/Bundle/CoreInstallerBundle/Stage/Upgrade/NotUpgradedStage.php b/src/lib/Zikula/Bundle/CoreInstallerBundle/Stage/Upgrade/NotUpgradedStage.php index acf03e131d..ef223f43e7 100644 --- a/src/lib/Zikula/Bundle/CoreInstallerBundle/Stage/Upgrade/NotUpgradedStage.php +++ b/src/lib/Zikula/Bundle/CoreInstallerBundle/Stage/Upgrade/NotUpgradedStage.php @@ -55,12 +55,12 @@ public function isNecessary() } // make sure selected language is installed $DBLocale = $this->fetchDBLocale(); - if (!in_array($DBLocale, \ZLanguage::getInstalledLanguages())) { + if (!in_array($DBLocale, $this->container->get('zikula_settings_module.locale_api')->getSupportedLocales())) { $variableApi = $this->container->get('zikula_extensions_module.api.variable'); $variableApi->set(VariableApi::CONFIG, 'language_i18n', 'en'); $variableApi->set(VariableApi::CONFIG, 'language', 'eng'); $variableApi->set(VariableApi::CONFIG, 'locale', 'en'); - \ZLanguage::setLocale('en'); + \ZLanguage::setLocale('en'); // @deprecated remove at Core-2.0 } return true; diff --git a/src/lib/Zikula/Bundle/FormExtensionBundle/Form/Type/LocaleType.php b/src/lib/Zikula/Bundle/FormExtensionBundle/Form/Type/LocaleType.php index ec343dbe1c..ae9d41cb47 100644 --- a/src/lib/Zikula/Bundle/FormExtensionBundle/Form/Type/LocaleType.php +++ b/src/lib/Zikula/Bundle/FormExtensionBundle/Form/Type/LocaleType.php @@ -22,10 +22,11 @@ class LocaleType extends AbstractType public function configureDefaultOptions(OptionsResolver $resolver) { $resolver->setDefaults([ - 'choices' => \ZLanguage::getInstalledLanguageNames(), + 'choices' => ['English' => 'en'], 'label' => __('Locale'), 'required' => false, - 'placeholder' => __('All') + 'placeholder' => __('All'), + 'choices_as_values' => true ]); } diff --git a/src/system/BlocksModule/Controller/AdminController.php b/src/system/BlocksModule/Controller/AdminController.php index 1e96d15a17..dff01591ad 100644 --- a/src/system/BlocksModule/Controller/AdminController.php +++ b/src/system/BlocksModule/Controller/AdminController.php @@ -68,7 +68,8 @@ public function viewAction(Request $request) 'method' => 'POST', 'translator' => $this->get('translator'), 'moduleChoices' => $this->get('zikula_blocks_module.api.block')->getModulesContainingBlocks(), - 'positionChoices' => $this->getDoctrine()->getRepository('ZikulaBlocksModule:BlockPositionEntity')->getPositionChoiceArray() + 'positionChoices' => $this->getDoctrine()->getRepository('ZikulaBlocksModule:BlockPositionEntity')->getPositionChoiceArray(), + 'localeChoices' => $this->get('zikula_settings_module.locale_api')->getSupportedLocaleNames() ]); $filterFormClone = clone $filterForm; diff --git a/src/system/BlocksModule/Form/Type/AdminViewFilterType.php b/src/system/BlocksModule/Form/Type/AdminViewFilterType.php index fabd707bf2..29384115e9 100644 --- a/src/system/BlocksModule/Form/Type/AdminViewFilterType.php +++ b/src/system/BlocksModule/Form/Type/AdminViewFilterType.php @@ -15,6 +15,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Zikula\BlocksModule\Api\BlockApi; +use Zikula\Common\Translator\IdentityTranslator; class AdminViewFilterType extends AbstractType { @@ -43,7 +44,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) ] ]) ->add('language', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', [ - 'choices' => \ZLanguage::getInstalledLanguageNames(), + 'choices' => $options['localeChoices'], + 'choices_as_values' => true, 'required' => false, 'placeholder' => $options['translator']->__('All'), 'attr' => [ @@ -52,9 +54,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]) ->add('active', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', [ 'choices' => [ - BlockApi::BLOCK_ACTIVE => $options['translator']->__('Active'), - BlockApi::BLOCK_INACTIVE => $options['translator']->__('Inactive'), + $options['translator']->__('Active') => BlockApi::BLOCK_ACTIVE, + $options['translator']->__('Inactive') => BlockApi::BLOCK_INACTIVE, ], + 'choices_as_values' => true, 'required' => false, 'placeholder' => $options['translator']->__('All'), 'attr' => [ @@ -88,9 +91,10 @@ public function configureOptions(OptionsResolver $resolver) 'attr' => [ 'class' => 'form form-inline', ], - 'translator' => null, + 'translator' => new IdentityTranslator(), 'moduleChoices' => [], - 'positionChoices' => [] + 'positionChoices' => [], + 'localeChoices' => ['English' => 'en'] ]); } } diff --git a/src/system/BlocksModule/Form/Type/BlockType.php b/src/system/BlocksModule/Form/Type/BlockType.php index dd46f5ce49..f73add5a66 100644 --- a/src/system/BlocksModule/Form/Type/BlockType.php +++ b/src/system/BlocksModule/Form/Type/BlockType.php @@ -17,6 +17,8 @@ use Zikula\BlocksModule\Api\BlockApi; use Zikula\BlocksModule\Api\BlockFilterApi; use Zikula\Bundle\FormExtensionBundle\Form\DataTransformer\NullToEmptyTransformer; +use Zikula\Common\Translator\TranslatorInterface; +use Zikula\SettingsModule\Api\LocaleApi; class BlockType extends AbstractType { @@ -31,21 +33,28 @@ class BlockType extends AbstractType private $blockFilterApi; /** - * @var + * @var TranslatorInterface */ private $translator; + /** + * @var LocaleApi + */ + private $localeApi; + /** * BlockType constructor. * @param BlockApi $blockApi * @param BlockFilterApi $blockFilterApi - * @param $translator + * @param TranslatorInterface $translator + * @param LocaleApi $localeApi */ - public function __construct(BlockApi $blockApi, BlockFilterApi $blockFilterApi, $translator) + public function __construct(BlockApi $blockApi, BlockFilterApi $blockFilterApi, TranslatorInterface $translator, LocaleApi $localeApi) { $this->blockApi = $blockApi; $this->blockFilterApi = $blockFilterApi; $this->translator = $translator; + $this->localeApi = $localeApi; } /** @@ -64,7 +73,8 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'required' => false ])->addModelTransformer(new NullToEmptyTransformer())) ->add($builder->create('language', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', [ - 'choices' => \ZLanguage::getInstalledLanguageNames(), + 'choices' => $this->localeApi->getSupportedLocaleNames(), + 'choices_as_values' => true, 'required' => false, 'placeholder' => $this->translator->__('All') ])->addModelTransformer(new NullToEmptyTransformer())) diff --git a/src/system/BlocksModule/Resources/config/services.yml b/src/system/BlocksModule/Resources/config/services.yml index f5d76916fb..8041cd82ac 100644 --- a/src/system/BlocksModule/Resources/config/services.yml +++ b/src/system/BlocksModule/Resources/config/services.yml @@ -45,7 +45,11 @@ services: zikula_blocks_module.form.block_type: class: "%zikula_blocks_module.form.block_type.class%" - arguments: ["@zikula_blocks_module.api.block", "@zikula_blocks_module.api.block_filter", "@translator.default"] + arguments: + - "@zikula_blocks_module.api.block" + - "@zikula_blocks_module.api.block_filter" + - "@translator.default" + - "@zikula_settings_module.locale_api" tags: - { name: form.type } diff --git a/src/system/CategoriesModule/Api/CategoryApi.php b/src/system/CategoriesModule/Api/CategoryApi.php index c74130d074..cc5aa0a96c 100644 --- a/src/system/CategoriesModule/Api/CategoryApi.php +++ b/src/system/CategoriesModule/Api/CategoryApi.php @@ -20,6 +20,7 @@ use Zikula\CategoriesModule\Helper\RelativeCategoryPathBuilderHelper; use Zikula\Common\Translator\TranslatorInterface; use Zikula\PermissionsModule\Api\PermissionApi; +use Zikula\SettingsModule\Api\LocaleApi; use ZLanguage; /** @@ -62,16 +63,22 @@ class CategoryApi */ private $pathBuilder; + /** + * @var LocaleApi + */ + private $localeApi; + /** * CategoryApi constructor. * - * @param TranslatorInterface $translator TranslatorInterface service instance - * @param EntityManager $entityManager EntityManager service instance - * @param RequestStack $requestStack RequestStack service instance - * @param PermissionApi $permissionApi PermissionApi service instance - * @param CategoryProcessingHelper $processingHelper CategoryProcessingHelper service instance - * @param CategorySortingHelper $sortingHelper CategorySortingHelper service instance - * @param RelativeCategoryPathBuilderHelper $pathBuilder RelativeCategoryPathBuilderHelper service instance + * @param TranslatorInterface $translator TranslatorInterface service instance + * @param EntityManager $entityManager EntityManager service instance + * @param RequestStack $requestStack RequestStack service instance + * @param PermissionApi $permissionApi PermissionApi service instance + * @param CategoryProcessingHelper $processingHelper CategoryProcessingHelper service instance + * @param CategorySortingHelper $sortingHelper CategorySortingHelper service instance + * @param RelativeCategoryPathBuilderHelper $pathBuilder RelativeCategoryPathBuilderHelper service instance + * @param LocaleApi $localeApi */ public function __construct( TranslatorInterface $translator, @@ -80,7 +87,8 @@ public function __construct( PermissionApi $permissionApi, CategoryProcessingHelper $processingHelper, CategorySortingHelper $sortingHelper, - RelativeCategoryPathBuilderHelper $pathBuilder + RelativeCategoryPathBuilderHelper $pathBuilder, + LocaleApi $localeApi ) { $this->translator = $translator; $this->entityManager = $entityManager; @@ -89,6 +97,7 @@ public function __construct( $this->processingHelper = $processingHelper; $this->sortingHelper = $sortingHelper; $this->pathBuilder = $pathBuilder; + $this->localeApi = $localeApi; } /** @@ -187,7 +196,7 @@ public function getCategoryById($categoryId) $cat = $category->toArray(); // set name and description by languages if not set - $languages = ZLanguage::getInstalledLanguages(); + $languages = $this->localeApi->getSupportedLocales();; foreach ($languages as $lang) { if (!isset($cat['display_name'][$lang])) { $cat['display_name'][$lang] = isset($cat['display_name']['en']) ? $cat['display_name']['en'] : ''; @@ -253,7 +262,7 @@ public function getCategories($where = '', $sort = '', $assocKey = '', $columnAr $categories = $this->entityManager->getRepository('ZikulaCategoriesModule:CategoryEntity')->freeSelect($where, $sort, $columnArray); $cats = []; - $languages = ZLanguage::getInstalledLanguages(); + $languages = $this->localeApi->getSupportedLocales();; foreach ($categories as $category) { $cat = $category->toArray(); diff --git a/src/system/CategoriesModule/Controller/AdminController.php b/src/system/CategoriesModule/Controller/AdminController.php index 34a2c75818..464d8f540f 100644 --- a/src/system/CategoriesModule/Controller/AdminController.php +++ b/src/system/CategoriesModule/Controller/AdminController.php @@ -168,7 +168,7 @@ public function editAction(Request $request, $cid = 0, $dr = 1, $mode = 'new') { $editCat = ''; - $languages = ZLanguage::getInstalledLanguages(); + $languages = $this->get('zikula_settings_module.locale_api')->getSupportedLocales(); $categoryApi = $this->get('zikula_categories_module.api.category'); // indicates that we're editing diff --git a/src/system/CategoriesModule/Controller/AjaxController.php b/src/system/CategoriesModule/Controller/AjaxController.php index 81d8918883..39648a4514 100644 --- a/src/system/CategoriesModule/Controller/AjaxController.php +++ b/src/system/CategoriesModule/Controller/AjaxController.php @@ -133,7 +133,7 @@ public function editAction(Request $request) 'mode' => $mode, 'category' => $editCat, 'attributes' => $attributes, - 'languages' => ZLanguage::getInstalledLanguages() + 'languages' => $this->get('zikula_settings_module.locale_api')->getSupportedLocales() ]; $result = [ diff --git a/src/system/CategoriesModule/Controller/UserController.php b/src/system/CategoriesModule/Controller/UserController.php index 4af8483726..c0b886eccc 100644 --- a/src/system/CategoriesModule/Controller/UserController.php +++ b/src/system/CategoriesModule/Controller/UserController.php @@ -183,7 +183,7 @@ public function editAction(Request $request) 'category' => $editCat, 'attributes' => $attributes, 'allCats' => $allCats, - 'languages' => ZLanguage::getInstalledLanguages(), + 'languages' => $this->get('zikula_settings_module.locale_api')->getSupportedLocales(), 'userlanguage' => $request->getLocale(), 'referer' => $request->getSession()->get('categories_referer'), 'csrfToken' => $this->get('zikula_core.common.csrf_token_handler')->generate() diff --git a/src/system/CategoriesModule/Helper/CategoryProcessingHelper.php b/src/system/CategoriesModule/Helper/CategoryProcessingHelper.php index 9eb841791a..926d3ed607 100644 --- a/src/system/CategoriesModule/Helper/CategoryProcessingHelper.php +++ b/src/system/CategoriesModule/Helper/CategoryProcessingHelper.php @@ -16,6 +16,7 @@ use Symfony\Component\HttpKernel\KernelInterface; use Zikula\CategoriesModule\Entity\CategoryEntity; use Zikula\Common\Translator\TranslatorInterface; +use Zikula\SettingsModule\Api\LocaleApi; use ZLanguage; /** @@ -38,18 +39,29 @@ class CategoryProcessingHelper */ private $kernel; + /** + * @var LocaleApi + */ + private $localeApi; + /** * CategoryProcessingHelper constructor. * - * @param TranslatorInterface $translator TranslatorInterface service instance - * @param EntityManager $entityManager EntityManager service instance - * @param KernelInterface $kernel KernelInterface service instance + * @param TranslatorInterface $translator TranslatorInterface service instance + * @param EntityManager $entityManager EntityManager service instance + * @param KernelInterface $kernel KernelInterface service instance + * @param LocaleApi $localeApi */ - public function __construct(TranslatorInterface $translator, EntityManager $entityManager, KernelInterface $kernel) - { + public function __construct( + TranslatorInterface $translator, + EntityManager $entityManager, + KernelInterface $kernel, + LocaleApi $localeApi + ) { $this->translator = $translator; $this->entityManager = $entityManager; $this->kernel = $kernel; + $this->localeApi = $localeApi; } /** @@ -125,7 +137,7 @@ public function processCategoryParent($parentId) */ public function processCategoryDisplayName($displayName, $name) { - $languages = ZLanguage::getInstalledLanguages(); + $languages = $this->localeApi->getSupportedLocales(); foreach ($languages as $lang) { if (!isset($displayName[$lang]) || !$displayName[$lang]) { $displayName[$lang] = $name; diff --git a/src/system/CategoriesModule/Resources/config/services.yml b/src/system/CategoriesModule/Resources/config/services.yml index 4ee10a4206..2bc293dbb8 100644 --- a/src/system/CategoriesModule/Resources/config/services.yml +++ b/src/system/CategoriesModule/Resources/config/services.yml @@ -26,7 +26,15 @@ services: zikula_categories_module.api.category: class: "%zikula_categories_module.api.category.class%" - arguments: ["@translator.default", "@doctrine.orm.entity_manager", "@request_stack", "@zikula_permissions_module.api.permission", "@zikula_categories_module.category_processing_helper", "@zikula_categories_module.category_sorting_helper", "@zikula_categories_module.relative_category_path_builder_helper"] + arguments: + - "@translator.default" + - "@doctrine.orm.entity_manager" + - "@request_stack" + - "@zikula_permissions_module.api.permission" + - "@zikula_categories_module.category_processing_helper" + - "@zikula_categories_module.category_sorting_helper" + - "@zikula_categories_module.relative_category_path_builder_helper" + - "@zikula_settings_module.locale_api" zikula_categories_module.api.category_permission: class: "%zikula_categories_module.api.category_permission.class%" @@ -42,7 +50,7 @@ services: zikula_categories_module.category_processing_helper: class: "%zikula_categories_module.category_processing_helper.class%" - arguments: ["@translator.default", "@doctrine.orm.entity_manager", "@kernel"] + arguments: ["@translator.default", "@doctrine.orm.entity_manager", "@kernel", "@zikula_settings_module.locale_api"] zikula_categories_module.category_sorting_helper: class: "%zikula_categories_module.category_sorting_helper.class%" diff --git a/src/system/ExtensionsModule/Helper/BundleSyncHelper.php b/src/system/ExtensionsModule/Helper/BundleSyncHelper.php index 7318a199c3..80d8b20ab1 100644 --- a/src/system/ExtensionsModule/Helper/BundleSyncHelper.php +++ b/src/system/ExtensionsModule/Helper/BundleSyncHelper.php @@ -194,7 +194,7 @@ public function scanForBundles(array $directories = []) // loads the gettext domain for 3rd party bundles if (!strpos($bundle->getPath(), 'bundles') === false) { - \ZLanguage::bindModuleDomain($bundle->getName()); + \ZLanguage::bindModuleDomain($bundle->getTranslationDomain()); } $bundleVersionArray['capabilities'] = serialize($bundleVersionArray['capabilities']); diff --git a/src/system/MailerModule/Controller/ConfigController.php b/src/system/MailerModule/Controller/ConfigController.php index f6d0b216a7..99fb9594f9 100644 --- a/src/system/MailerModule/Controller/ConfigController.php +++ b/src/system/MailerModule/Controller/ConfigController.php @@ -42,7 +42,8 @@ public function configAction(Request $request) $form = $this->createForm('Zikula\MailerModule\Form\Type\ConfigType', $this->getDataValues(), [ - 'translator' => $this->get('translator.default') + 'translator' => $this->get('translator.default'), + 'charset' => $this->container->get('kernel')->getCharset() ] ); diff --git a/src/system/MailerModule/Form/Type/ConfigType.php b/src/system/MailerModule/Form/Type/ConfigType.php index ea8a9939e8..f95f2c1af7 100644 --- a/src/system/MailerModule/Form/Type/ConfigType.php +++ b/src/system/MailerModule/Form/Type/ConfigType.php @@ -60,7 +60,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) ->add('charset', 'Symfony\Component\Form\Extension\Core\Type\TextType', [ 'label' => $translator->__('Character set'), 'max_length' => 20, - 'help' => $translator->__f("Default: '%s'", ['%s' => 'utf-8' /* @todo! \ZLanguage::getEncoding() */]) + 'help' => $translator->__f("Default: '%s'", ['%s' => $options['charset']]) ]) ->add('encoding', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', [ 'label' => $translator->__('Encoding'), @@ -175,7 +175,8 @@ public function getBlockPrefix() public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ - 'translator' => null + 'translator' => null, + 'charset' => 'utf-8' ]); } } diff --git a/src/system/RoutesModule/Helper/MultilingualRoutingHelper.php b/src/system/RoutesModule/Helper/MultilingualRoutingHelper.php index ada80deaff..c181bd3d89 100644 --- a/src/system/RoutesModule/Helper/MultilingualRoutingHelper.php +++ b/src/system/RoutesModule/Helper/MultilingualRoutingHelper.php @@ -15,6 +15,7 @@ use Zikula\Bundle\CoreBundle\CacheClearer; use Zikula\Bundle\CoreBundle\DynamicConfigDumper; use Zikula\ExtensionsModule\Api\VariableApi; +use Zikula\SettingsModule\Api\LocaleApi; class MultilingualRoutingHelper { @@ -33,6 +34,11 @@ class MultilingualRoutingHelper */ private $cacheClearer; + /** + * @var LocaleApi + */ + private $localeApi; + /** * @var string */ @@ -40,16 +46,23 @@ class MultilingualRoutingHelper /** * MultilingualRoutingHelper constructor. - * @param VariableApi $variableApi + * @param VariableApi $variableApi * @param DynamicConfigDumper $configDumper - * @param CacheClearer $cacheClearer - * @param string $locale + * @param CacheClearer $cacheClearer + * @param LocaleApi $localeApi + * @param string $locale */ - public function __construct(VariableApi $variableApi, DynamicConfigDumper $configDumper, CacheClearer $cacheClearer, $locale) - { + public function __construct( + VariableApi $variableApi, + DynamicConfigDumper $configDumper, + CacheClearer $cacheClearer, + LocaleApi $localeApi, + $locale + ) { $this->variableApi = $variableApi; $this->configDumper = $configDumper; $this->cacheClearer = $cacheClearer; + $this->localeApi = $localeApi; $this->locale = $locale; } @@ -61,7 +74,7 @@ public function __construct(VariableApi $variableApi, DynamicConfigDumper $confi public function reloadMultilingualRoutingSettings() { $defaultLocale = $this->variableApi->getSystemVar('language_i18n', $this->locale); - $installedLanguages = \ZLanguage::getInstalledLanguages(); + $installedLanguages = $this->localeApi->getSupportedLocales(); $isRequiredLangParameter = $this->variableApi->getSystemVar('languageurl', 0); $this->configDumper->setConfiguration('jms_i18n_routing', [ diff --git a/src/system/RoutesModule/Helper/RouteDumperHelper.php b/src/system/RoutesModule/Helper/RouteDumperHelper.php index db7f62e11b..48ec53783d 100644 --- a/src/system/RoutesModule/Helper/RouteDumperHelper.php +++ b/src/system/RoutesModule/Helper/RouteDumperHelper.php @@ -44,19 +44,19 @@ public function __construct(ContainerInterface $container) public function dumpJsRoutes($lang = null) { // determine list of supported languages - $langs = []; - $installedLanguages = \ZLanguage::getInstalledLanguages(); + $variableApi = $this->container->get('zikula_extensions_module.api.variable'); + $installedLanguages = $this->container->get('zikula_settings_module.locale_api')->getSupportedLocales(); if (isset($lang) && in_array($lang, $installedLanguages)) { // use provided lang if available $langs = [$lang]; } else { - $multilingual = (bool)\System::getVar('multilingual', 0); + $multilingual = (bool)$variableApi->getSystemVar('multilingual', false); if ($multilingual) { // get all available locales $langs = $installedLanguages; } else { // get only the default locale - $langs = [\System::getVar('language_i18n', 'en')]; //$this->container->getParameter('locale'); + $langs = [$variableApi->getSystemVar('language_i18n', 'en')]; //$this->container->getParameter('locale'); } } diff --git a/src/system/RoutesModule/Resources/config/helpers.yml b/src/system/RoutesModule/Resources/config/helpers.yml index f970e9c4d5..0939fc79af 100644 --- a/src/system/RoutesModule/Resources/config/helpers.yml +++ b/src/system/RoutesModule/Resources/config/helpers.yml @@ -3,27 +3,32 @@ services: zikula_routes_module.controller_helper: class: Zikula\RoutesModule\Helper\ControllerHelper arguments: ["@service_container", "@translator.default", "@session", "@logger"] - + zikula_routes_module.listentries_helper: class: Zikula\RoutesModule\Helper\ListEntriesHelper arguments: ["@translator.default"] - + zikula_routes_module.model_helper: class: Zikula\RoutesModule\Helper\ModelHelper arguments: ["@service_container"] - + zikula_routes_module.selection_helper: class: Zikula\RoutesModule\Helper\SelectionHelper arguments: ["@service_container", "@doctrine.orm.entity_manager", "@translator.default", "@zikula_routes_module.controller_helper"] - + zikula_routes_module.view_helper: class: Zikula\RoutesModule\Helper\ViewHelper arguments: ["@service_container", "@translator.default"] - + zikula_routes_module.workflow_helper: class: Zikula\RoutesModule\Helper\WorkflowHelper arguments: ["@service_container", "@translator.default"] zikula_routes_module.multilingual_routing_helper: class: Zikula\RoutesModule\Helper\MultilingualRoutingHelper - arguments: ["@zikula_extensions_module.api.variable", "@zikula.dynamic_config_dumper", "@zikula.cache_clearer", '%locale%'] + arguments: + - "@zikula_extensions_module.api.variable" + - "@zikula.dynamic_config_dumper" + - "@zikula.cache_clearer" + - "@zikula_settings_module.locale_api" + - '%locale%' diff --git a/src/system/SettingsModule/Api/LocaleApi.php b/src/system/SettingsModule/Api/LocaleApi.php index 9bac029fa9..e4d7cc5861 100644 --- a/src/system/SettingsModule/Api/LocaleApi.php +++ b/src/system/SettingsModule/Api/LocaleApi.php @@ -32,18 +32,21 @@ public function getSupportedLocales() if (empty($this->supportedLocales)) { $this->supportedLocales[] = 'en'; $finder = new Finder(); - $files = $finder->files() - ->in(['app/Resources/translations']) - ->depth(0) - ->name('*.po') - ->notName('*.template.*'); - foreach ($files as $file) { - $fileName = $file->getBasename('.po'); - list($domain, $locale) = explode('.', $fileName); - if (!in_array($locale, $this->supportedLocales)) { - $this->supportedLocales[] = $locale; + if (is_dir('app/Resources/translations')) { + $files = $finder->files() + ->in(['app/Resources/translations']) + ->depth(0) + ->name('*.po') + ->notName('*.template.*'); + foreach ($files as $file) { + $fileName = $file->getBasename('.po'); + list($domain, $locale) = explode('.', $fileName); + if (!in_array($locale, $this->supportedLocales)) { + $this->supportedLocales[] = $locale; + } } } + $this->addLegacyLocales(); // @deprecated remove at Core-2.0 } return $this->supportedLocales; @@ -64,4 +67,18 @@ public function getSupportedLocaleNames() return $namedLocales; } + + /** + * Read legacy locale.ini files and add those locales + * @deprecated remove at Core-2.0 + */ + private function addLegacyLocales() + { + $legacyLocales = \ZLanguage::getInstalledLanguages(); + foreach ($legacyLocales as $locale) { + if (!in_array($locale, $this->supportedLocales)) { + $this->supportedLocales[] = $locale; + } + } + } } diff --git a/src/system/SettingsModule/Controller/SettingsController.php b/src/system/SettingsModule/Controller/SettingsController.php index 13605b8227..b05b686f91 100644 --- a/src/system/SettingsModule/Controller/SettingsController.php +++ b/src/system/SettingsModule/Controller/SettingsController.php @@ -47,7 +47,7 @@ public function mainAction(Request $request) throw new AccessDeniedException(); } - $installedLanguageNames = ZLanguage::getInstalledLanguageNames(); + $installedLanguageNames = $this->get('zikula_settings_module.locale_api')->getSupportedLocaleNames(); $capabilityApi = $this->get('zikula_extensions_module.api.capability'); $userModules = $capabilityApi->getExtensionsCapableOf(CapabilityApiInterface::USER); @@ -110,7 +110,7 @@ public function localeAction(Request $request) ], [ 'translator' => $this->get('translator.default'), - 'languages' => ZLanguage::getInstalledLanguageNames(), + 'languages' => $this->container->get('zikula_settings_module.locale_api')->getSupportedLocaleNames(), 'timezones' => DateUtil::getTimezones() ] ); diff --git a/src/system/SettingsModule/Form/Type/LocaleSettingsType.php b/src/system/SettingsModule/Form/Type/LocaleSettingsType.php index 0e6a7360f2..3974d6d2cc 100644 --- a/src/system/SettingsModule/Form/Type/LocaleSettingsType.php +++ b/src/system/SettingsModule/Form/Type/LocaleSettingsType.php @@ -37,9 +37,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'label' => $translator->__('Prepend language to URL'), 'expanded' => true, 'choices' => [ - 1 => $translator->__('Always'), - 0 => $translator->__('Only for non-default languages'), - ] + $translator->__('Always') => 1, + $translator->__('Only for non-default languages') => 0, + ], + 'choices_as_values' => true ]) ->add('language_detect', 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', [ 'label' => $translator->__('Automatically detect language from browser settings'), @@ -48,9 +49,10 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]) ->add('language_i18n', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', [ 'label' => $translator->__('Default language to use for this site'), - 'choices' => $options['languages'] + 'choices' => $options['languages'], + 'choices_as_values' => true ]) - ->add('timezone_offset', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', [ + ->add('timezone_offset', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', [ // @todo convert to TimezoneType 'choices' => $options['timezones'], 'label' => $translator->__('Time zone for anonymous guests'), 'help' => $translator->__('Server time zone') . ': ' . DateUtil::getTimezoneAbbr() @@ -94,8 +96,8 @@ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'translator' => null, - 'languages' => [], - 'timezones' => [] + 'languages' => ["English" => 'en'], + 'timezones' => [0 => "GMT"] ]); } } diff --git a/src/system/SettingsModule/Form/Type/MainSettingsType.php b/src/system/SettingsModule/Form/Type/MainSettingsType.php index d8fac8c5ab..cb60919dbd 100644 --- a/src/system/SettingsModule/Form/Type/MainSettingsType.php +++ b/src/system/SettingsModule/Form/Type/MainSettingsType.php @@ -193,7 +193,7 @@ function ($submittedPageTitle) use ($translator) { ] ]) ; - foreach ($options['languages'] as $languageCode => $language) { + foreach ($options['languages'] as $language => $languageCode) { $builder ->add('sitename_' . $languageCode, 'Symfony\Component\Form\Extension\Core\Type\TextType', [ 'label' => $translator->__('Site name') diff --git a/src/system/SettingsModule/Resources/views/Settings/main.html.twig b/src/system/SettingsModule/Resources/views/Settings/main.html.twig index f9c8160367..5046d768d7 100644 --- a/src/system/SettingsModule/Resources/views/Settings/main.html.twig +++ b/src/system/SettingsModule/Resources/views/Settings/main.html.twig @@ -18,13 +18,13 @@ {{ __('Main info') }}
{# Tab panes #} - {% for languageCode, language in languages %} + {% for language, languageCode in languages %}
{{ form_row(form['sitename_' ~ languageCode]) }} {{ form_row(form['slogan_' ~ languageCode]) }} @@ -45,13 +45,13 @@ {{ __('Meta tag settings') }}
{# Tab panes #} - {% for languageCode, language in languages %} + {% for language, languageCode in languages %}
{{ form_row(form['defaultpagetitle_' ~ languageCode]) }} {{ form_row(form['defaultmetadescription_' ~ languageCode]) }} diff --git a/src/system/SettingsModule/SettingsModuleInstaller.php b/src/system/SettingsModule/SettingsModuleInstaller.php index 28c7e1dc9f..5c2cc147f5 100644 --- a/src/system/SettingsModule/SettingsModuleInstaller.php +++ b/src/system/SettingsModule/SettingsModuleInstaller.php @@ -64,7 +64,7 @@ public function install() $this->setSystemVar('shorturlstype', '0'); $this->setSystemVar('shorturlsseparator', '-'); // Multilingual support - foreach (ZLanguage::getInstalledLanguages() as $lang) { + foreach ($this->container->get('zikula_settings_module.locale_api')->getSupportedLocales() as $lang) { $this->setSystemVar('sitename_' . $lang, $this->__('Site name')); $this->setSystemVar('slogan_' . $lang, $this->__('Site description')); $this->setSystemVar('metakeywords_' . $lang, $this->__('zikula, portal, open source, web site, website, weblog, blog, content management system, cms, application framework')); @@ -131,6 +131,7 @@ public function install() */ public function upgrade($oldversion) { + $request = $this->container->get('request_stack')->getMasterRequest(); // Upgrade dependent on old version number switch ($oldversion) { case '2.9.7': @@ -145,7 +146,7 @@ public function upgrade($oldversion) } $locale = $this->getSystemVar('locale'); if (empty($locale)) { - $this->setSystemVar('locale', ZLanguage::getLocale()); + $this->setSystemVar('locale', $request->getLocale()); } case '2.9.9': @@ -156,7 +157,7 @@ public function upgrade($oldversion) /** @var \Zikula\ExtensionsModule\Entity\ExtensionVarEntity $modVar */ foreach ($SystemVars as $modVar) { if (in_array($modVar->getName(), $varsToChange)) { - foreach (ZLanguage::getInstalledLanguages() as $langcode) { + foreach ($this->container->get('zikula_settings_module.locale_api')->getSupportedLocales() as $langcode) { $newModVar = clone $modVar; $newModVar->setName($modVar->getName() . '_' . $langcode); $this->entityManager->persist($newModVar); diff --git a/src/system/ThemeModule/Helper/BundleSyncHelper.php b/src/system/ThemeModule/Helper/BundleSyncHelper.php index 1881cf698a..08c96f6923 100644 --- a/src/system/ThemeModule/Helper/BundleSyncHelper.php +++ b/src/system/ThemeModule/Helper/BundleSyncHelper.php @@ -136,7 +136,7 @@ public function regenerate() $themeVersionArray['directory'] = implode('/', $directory); // loads the gettext domain for theme - \ZLanguage::bindThemeDomain($bundle->getName()); + \ZLanguage::bindThemeDomain($bundle->getTranslationDomain()); // set defaults for all themes $themeVersionArray['type'] = 3; diff --git a/src/system/UsersModule/Container/LinkContainer.php b/src/system/UsersModule/Container/LinkContainer.php index 75cf1166a5..0f8c3fd7f4 100644 --- a/src/system/UsersModule/Container/LinkContainer.php +++ b/src/system/UsersModule/Container/LinkContainer.php @@ -16,6 +16,7 @@ use Zikula\Core\LinkContainer\LinkContainerInterface; use Zikula\ExtensionsModule\Api\VariableApi; use Zikula\PermissionsModule\Api\PermissionApi; +use Zikula\SettingsModule\Api\LocaleApi; use Zikula\UsersModule\Api\CurrentUserApi; use Zikula\UsersModule\Constant as UsersConstant; use Zikula\UsersModule\Helper\RegistrationHelper; @@ -52,6 +53,11 @@ class LinkContainer implements LinkContainerInterface */ private $currentUser; + /** + * @var LocaleApi + */ + private $localeApi; + /** * constructor. * @@ -61,6 +67,7 @@ class LinkContainer implements LinkContainerInterface * @param VariableApi $variableApi * @param RegistrationHelper $registrationHelper * @param CurrentUserApi $currentUserApi + * @param LocaleApi $localeApi */ public function __construct( TranslatorInterface $translator, @@ -68,7 +75,8 @@ public function __construct( PermissionApi $permissionApi, VariableApi $variableApi, RegistrationHelper $registrationHelper, - CurrentUserApi $currentUserApi + CurrentUserApi $currentUserApi, + LocaleApi $localeApi ) { $this->translator = $translator; $this->router = $router; @@ -76,6 +84,7 @@ public function __construct( $this->variableApi = $variableApi; $this->registrationHelper = $registrationHelper; $this->currentUser = $currentUserApi; + $this->localeApi = $localeApi; } /** @@ -185,7 +194,8 @@ private function getAccount() } if ($this->variableApi->getSystemVar('multilingual')) { - if (count(\ZLanguage::getInstalledLanguages()) > 1) { + $locales = $this->localeApi->getSupportedLocales(); + if (count($locales) > 1) { $links[] = [ 'url' => $this->router->generate('zikulausersmodule_account_changelanguage'), 'text' => $this->translator->__('Language switcher'), diff --git a/src/system/UsersModule/Controller/AccountController.php b/src/system/UsersModule/Controller/AccountController.php index c450758deb..ccded886a0 100644 --- a/src/system/UsersModule/Controller/AccountController.php +++ b/src/system/UsersModule/Controller/AccountController.php @@ -53,11 +53,11 @@ public function changeLanguageAction(Request $request) if (!$this->get('zikula_users_module.current_user')->isLoggedIn()) { throw new AccessDeniedException(); } - $installedLanguages = \ZLanguage::getInstalledLanguageNames(); + $installedLanguages = $this->get('zikula_settings_module.locale_api')->getSupportedLocaleNames(); $form = $this->createFormBuilder() ->add('language', 'Symfony\Component\Form\Extension\Core\Type\ChoiceType', [ 'label' => $this->__('Choose language'), - 'choices' => array_flip($installedLanguages), + 'choices' => $installedLanguages, 'choices_as_values' => true, 'placeholder' => $this->__('Site default'), 'required' => false, @@ -80,7 +80,7 @@ public function changeLanguageAction(Request $request) $data = $form->getData(); if ($data['language']) { $request->getSession()->set('language', $data['language']); - $this->addFlash('success', $this->__f('Language changed to %lang', ['%lang' => $installedLanguages[$data['language']]])); + $this->addFlash('success', $this->__f('Language changed to %lang', ['%lang' => array_search($data['language'], $installedLanguages[])])); } else { $request->getSession()->remove('language'); $this->addFlash('success', $this->__('Language set to site default.')); diff --git a/src/system/UsersModule/Resources/config/services.yml b/src/system/UsersModule/Resources/config/services.yml index f6cf24f035..a2bf2f1769 100644 --- a/src/system/UsersModule/Resources/config/services.yml +++ b/src/system/UsersModule/Resources/config/services.yml @@ -43,6 +43,13 @@ services: zikula_users_module.container.link_container: class: "%zikula_users_module.container.link_container.class%" - arguments: ["@translator.default", "@router", "@zikula_permissions_module.api.permission", "@zikula_extensions_module.api.variable", "@zikula_users_module.helper.registration_helper", "@zikula_users_module.current_user"] + arguments: + - "@translator.default" + - "@router" + - "@zikula_permissions_module.api.permission" + - "@zikula_extensions_module.api.variable" + - "@zikula_users_module.helper.registration_helper" + - "@zikula_users_module.current_user" + - "@zikula_settings_module.locale_api" tags: - { name: zikula.link_container } From e88109c3b30efc8ef09d82a295486eec09e6a695 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 4 Jan 2017 19:08:15 -0500 Subject: [PATCH 6/9] ci --- src/system/CategoriesModule/Api/CategoryApi.php | 5 ++--- src/system/CategoriesModule/Controller/AdminController.php | 1 - src/system/CategoriesModule/Controller/AjaxController.php | 1 - src/system/CategoriesModule/Controller/UserController.php | 1 - .../CategoriesModule/Helper/CategoryProcessingHelper.php | 1 - src/system/SettingsModule/Controller/SettingsController.php | 1 - 6 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/system/CategoriesModule/Api/CategoryApi.php b/src/system/CategoriesModule/Api/CategoryApi.php index cc5aa0a96c..16b1914a28 100644 --- a/src/system/CategoriesModule/Api/CategoryApi.php +++ b/src/system/CategoriesModule/Api/CategoryApi.php @@ -21,7 +21,6 @@ use Zikula\Common\Translator\TranslatorInterface; use Zikula\PermissionsModule\Api\PermissionApi; use Zikula\SettingsModule\Api\LocaleApi; -use ZLanguage; /** * CategoryApi @@ -196,7 +195,7 @@ public function getCategoryById($categoryId) $cat = $category->toArray(); // set name and description by languages if not set - $languages = $this->localeApi->getSupportedLocales();; + $languages = $this->localeApi->getSupportedLocales(); foreach ($languages as $lang) { if (!isset($cat['display_name'][$lang])) { $cat['display_name'][$lang] = isset($cat['display_name']['en']) ? $cat['display_name']['en'] : ''; @@ -262,7 +261,7 @@ public function getCategories($where = '', $sort = '', $assocKey = '', $columnAr $categories = $this->entityManager->getRepository('ZikulaCategoriesModule:CategoryEntity')->freeSelect($where, $sort, $columnArray); $cats = []; - $languages = $this->localeApi->getSupportedLocales();; + $languages = $this->localeApi->getSupportedLocales(); foreach ($categories as $category) { $cat = $category->toArray(); diff --git a/src/system/CategoriesModule/Controller/AdminController.php b/src/system/CategoriesModule/Controller/AdminController.php index 464d8f540f..7e111b2c6e 100644 --- a/src/system/CategoriesModule/Controller/AdminController.php +++ b/src/system/CategoriesModule/Controller/AdminController.php @@ -22,7 +22,6 @@ use Symfony\Component\HttpKernel\HttpKernelInterface; use Zikula\CategoriesModule\Entity\CategoryEntity; use Zikula\Core\Controller\AbstractController; -use ZLanguage; /** * @Route("/admin") diff --git a/src/system/CategoriesModule/Controller/AjaxController.php b/src/system/CategoriesModule/Controller/AjaxController.php index 39648a4514..26e8c9bc7d 100644 --- a/src/system/CategoriesModule/Controller/AjaxController.php +++ b/src/system/CategoriesModule/Controller/AjaxController.php @@ -20,7 +20,6 @@ use Zikula\Core\Response\Ajax\BadDataResponse; use Zikula\Core\Response\Ajax\ForbiddenResponse; use Zikula\Core\Response\Ajax\NotFoundResponse; -use ZLanguage; /** * @Route("/ajax") diff --git a/src/system/CategoriesModule/Controller/UserController.php b/src/system/CategoriesModule/Controller/UserController.php index c0b886eccc..75d28e8d83 100644 --- a/src/system/CategoriesModule/Controller/UserController.php +++ b/src/system/CategoriesModule/Controller/UserController.php @@ -22,7 +22,6 @@ use System; use Zikula\CategoriesModule\Entity\CategoryEntity; use Zikula\Core\Controller\AbstractController; -use ZLanguage; /** * User controllers for the categories module. diff --git a/src/system/CategoriesModule/Helper/CategoryProcessingHelper.php b/src/system/CategoriesModule/Helper/CategoryProcessingHelper.php index 926d3ed607..e5e8dc1beb 100644 --- a/src/system/CategoriesModule/Helper/CategoryProcessingHelper.php +++ b/src/system/CategoriesModule/Helper/CategoryProcessingHelper.php @@ -17,7 +17,6 @@ use Zikula\CategoriesModule\Entity\CategoryEntity; use Zikula\Common\Translator\TranslatorInterface; use Zikula\SettingsModule\Api\LocaleApi; -use ZLanguage; /** * Category processing helper functions for the categories module. diff --git a/src/system/SettingsModule/Controller/SettingsController.php b/src/system/SettingsModule/Controller/SettingsController.php index b05b686f91..eaf30e52f2 100644 --- a/src/system/SettingsModule/Controller/SettingsController.php +++ b/src/system/SettingsModule/Controller/SettingsController.php @@ -24,7 +24,6 @@ use Zikula\ExtensionsModule\Api\VariableApi; use Zikula\ExtensionsModule\Entity\ExtensionEntity; use Zikula\ThemeModule\Engine\Annotation\Theme; -use ZLanguage; /** * Class SettingsController From 04a72b17cc02b797ce826854c5f244c70cf7eddd Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 4 Jan 2017 20:53:43 -0500 Subject: [PATCH 7/9] remove unused method --- .../Helper/ControllerHelper.php | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/src/lib/Zikula/Bundle/CoreInstallerBundle/Helper/ControllerHelper.php b/src/lib/Zikula/Bundle/CoreInstallerBundle/Helper/ControllerHelper.php index 4189590e3a..bcf3e4205c 100644 --- a/src/lib/Zikula/Bundle/CoreInstallerBundle/Helper/ControllerHelper.php +++ b/src/lib/Zikula/Bundle/CoreInstallerBundle/Helper/ControllerHelper.php @@ -136,30 +136,4 @@ public function writeEncodedAdminCredentials(YamlDumper $yamlManager, array $dat throw new AbortStageException(__f('Cannot write parameters to %s file.', 'custom_parameters.yml')); } } - - /** - * @TODO unused at the moment. probably is needed in the controller to display translations? - * Load the right language. - * - * @return string - */ - public function setupLang(ContainerInterface $container) - { - $lang = 'en'; - // @TODO read this from parameters, not ini - if (is_readable('config/installer.ini')) { - $ini = parse_ini_file('config/installer.ini'); - $lang = isset($ini['language']) ? $ini['language'] : 'en'; - } - - // setup multilingual - $GLOBALS['ZConfig']['System']['language_i18n'] = $lang; - $GLOBALS['ZConfig']['System']['multilingual'] = true; - $GLOBALS['ZConfig']['System']['languageurl'] = true; - $GLOBALS['ZConfig']['System']['language_detect'] = false; - $container->loadArguments($GLOBALS['ZConfig']['System']); - - $zLang = \ZLanguage::getInstance(); - $zLang->setup($container->get('request')); - } } From bacc2cefb90c775ec2ba5237190abf9cb07a00e3 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 4 Jan 2017 20:59:10 -0500 Subject: [PATCH 8/9] remove additional unneeded usages of ZLanguage --- src/system/ExtensionsModule/Helper/BundleSyncHelper.php | 6 ------ src/system/ExtensionsModule/Helper/ExtensionHelper.php | 5 ----- src/system/MailerModule/Api/UserApi.php | 2 +- src/system/ThemeModule/Helper/BundleSyncHelper.php | 3 --- 4 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/system/ExtensionsModule/Helper/BundleSyncHelper.php b/src/system/ExtensionsModule/Helper/BundleSyncHelper.php index 80d8b20ab1..aee1e7a6c3 100644 --- a/src/system/ExtensionsModule/Helper/BundleSyncHelper.php +++ b/src/system/ExtensionsModule/Helper/BundleSyncHelper.php @@ -191,12 +191,6 @@ public function scanForBundles(array $directories = []) if (empty($bundleVersionArray['capabilities']['user']) && file_exists($bundle->getPath().'/Controller/UserController.php')) { $bundleVersionArray['capabilities']['user'] = ['url' => \ModUtil::url($bundle->getName(), 'user', 'index')]; } - - // loads the gettext domain for 3rd party bundles - if (!strpos($bundle->getPath(), 'bundles') === false) { - \ZLanguage::bindModuleDomain($bundle->getTranslationDomain()); - } - $bundleVersionArray['capabilities'] = serialize($bundleVersionArray['capabilities']); $bundleVersionArray['securityschema'] = serialize($bundleVersionArray['securityschema']); $bundleVersionArray['dependencies'] = serialize($bundleVersionArray['dependencies']); diff --git a/src/system/ExtensionsModule/Helper/ExtensionHelper.php b/src/system/ExtensionsModule/Helper/ExtensionHelper.php index 2766981405..f46b072b99 100644 --- a/src/system/ExtensionsModule/Helper/ExtensionHelper.php +++ b/src/system/ExtensionsModule/Helper/ExtensionHelper.php @@ -281,11 +281,6 @@ private function forceLoadExtension(ExtensionEntity $extension) // moduleMetaData only exists for bundle-type modules $boot = new \Zikula\Bundle\CoreBundle\Bundle\Bootstrap(); $boot->addAutoloaders($this->container->get('kernel'), $moduleMetaData->getAutoload()); - if ($extension->getType() == self::TYPE_MODULE) { - if (is_dir("modules/$osDir/Resources/locale")) { - \ZLanguage::bindModuleDomain($extension->getName()); - } - } $moduleClass = $moduleMetaData->getClass(); $bundle = new $moduleClass(); diff --git a/src/system/MailerModule/Api/UserApi.php b/src/system/MailerModule/Api/UserApi.php index 4a8a1bc48d..8a6c34d175 100644 --- a/src/system/MailerModule/Api/UserApi.php +++ b/src/system/MailerModule/Api/UserApi.php @@ -78,7 +78,7 @@ public function sendmessage($args) $mailer = $this->getContainer()->get('zikula_mailer_module.api.mailer'); $variableApi = $this->getContainer()->get('zikula_extensions_module.api.variable'); - $sitename = $variableApi->getSystemVar('sitename_' . ZLanguage::getLanguageCode(), $variableApi->getSystemVar('sitename_en')); + $sitename = $variableApi->getSystemVar('sitename'); $adminMail = $variableApi->getSystemVar('adminmail'); // create new message instance diff --git a/src/system/ThemeModule/Helper/BundleSyncHelper.php b/src/system/ThemeModule/Helper/BundleSyncHelper.php index 08c96f6923..a2c866591d 100644 --- a/src/system/ThemeModule/Helper/BundleSyncHelper.php +++ b/src/system/ThemeModule/Helper/BundleSyncHelper.php @@ -135,9 +135,6 @@ public function regenerate() array_shift($directory); $themeVersionArray['directory'] = implode('/', $directory); - // loads the gettext domain for theme - \ZLanguage::bindThemeDomain($bundle->getTranslationDomain()); - // set defaults for all themes $themeVersionArray['type'] = 3; $themeVersionArray['state'] = ThemeEntityRepository::STATE_INACTIVE; From f84b5527425a8ce38d2bf57605020ffb7bf05e57 Mon Sep 17 00:00:00 2001 From: Craig Heydenburg Date: Wed, 4 Jan 2017 21:00:00 -0500 Subject: [PATCH 9/9] ci --- src/system/MailerModule/Api/UserApi.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/system/MailerModule/Api/UserApi.php b/src/system/MailerModule/Api/UserApi.php index 8a6c34d175..c77941c642 100644 --- a/src/system/MailerModule/Api/UserApi.php +++ b/src/system/MailerModule/Api/UserApi.php @@ -12,7 +12,6 @@ namespace Zikula\MailerModule\Api; use Swift_Message; -use ZLanguage; /** * API functions used by user controllers