From 1944101496b172c0954e1b1a030aff408f8cc060 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 27 Apr 2018 23:54:47 +0300 Subject: [PATCH] Using I18n Component --- composer.json | 3 ++- flextype/Plugins.php | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 75c7616b..2a367e1c 100755 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "flextype-components/token" : "1.*", "flextype-components/filesystem" : "1.*", "flextype-components/event" : "1.*", - "flextype-components/view" : "1.*" + "flextype-components/view" : "1.*", + "flextype-components/i18n" : "dev-master" }, "autoload": { "classmap": [ diff --git a/flextype/Plugins.php b/flextype/Plugins.php index b38ba1a4..d25a276a 100755 --- a/flextype/Plugins.php +++ b/flextype/Plugins.php @@ -24,6 +24,46 @@ class Plugins */ protected static $instance = null; + /** + * Locales array + * + * @var array + */ + public static $locales = [ + 'ar' => 'العربية', + 'bg' => 'Български', + 'ca' => 'Català', + 'cs' => 'Česky', + 'da' => 'Dansk', + 'de' => 'Deutsch', + 'el' => 'Ελληνικά', + 'en' => 'English', + 'es' => 'Español', + 'fa' => 'Farsi', + 'fi' => 'Suomi', + 'fr' => 'Français', + 'gl' => 'Galego', + 'ka-ge' => 'Georgian', + 'hu' => 'Magyar', + 'it' => 'Italiano', + 'id' => 'Bahasa Indonesia', + 'ja' => '日本語', + 'lt' => 'Lietuvių', + 'nl' => 'Nederlands', + 'no' => 'Norsk', + 'pl' => 'Polski', + 'pt' => 'Português', + 'pt-br' => 'Português do Brasil', + 'ru' => 'Русский', + 'sk' => 'Slovenčina', + 'sl' => 'Slovenščina', + 'sv' => 'Svenska', + 'sr' => 'Srpski', + 'tr' => 'Türkçe', + 'uk' => 'Українська', + 'zh-cn' => '简体中文', + ]; + /** * Protected constructor since this is a static class. * @@ -88,6 +128,18 @@ class Plugins } } + // Create dictionary + if (is_array($plugins_list) && count($plugins_list) > 0) { + foreach (static::$locales as $locale => $locale_title) { + foreach ($plugins_list as $plugin) { + $language_file = PLUGINS_PATH . '/' . $plugin . '/languages/' . $locale . '.yml'; + if (Filesystem::fileExists($language_file)) { + I18n::add($plugin, $locale, Yaml::parseFile($language_file)); + } + } + } + } + // Include enabled plugins if (is_array(Config::get('plugins')) && count(Config::get('plugins')) > 0) { foreach (Config::get('plugins') as $plugin_name => $plugin) {