We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32241
    • 1,495 Posts
    I actually want to add localization library, but I decided not to, due to the fact that it can be just a simple php file containing all the 2 dimensional array needed for each languages. I’m looking for a better way to this. I heard that Ryan wanting to have this implemented on the core, to have the language stored on MySql.

    Any thought on this?
      Wendy Novianto
      [font=Verdana]PT DJAMOER Technology Media
      [font=Verdana]Xituz Media
      • 6726
      • 7,075 Posts
      Some CMS I have used had a simple web based interface to edit those php arrays you mention (bitweaver is one, e107 is another) : it’s convenient, user friendly and less heavy than those .po files like you have in Drupal or WordPress that require poedit.

      The idea would be to have a tab in the manager that give you the ability to edit those arrays for whatever language you choose to create/edit a translation for... it’s by far the best way I have experienced.
        .: COO - Commerce Guys - Community Driven Innovation :.


        MODx est l'outil id
        • 32241
        • 1,495 Posts
        Thanks david, that’s kinda give me the idea to do it.

        I’ll look into this. Maybe creating a module will be better suited, what do you think? As far as library goes, it’s more about to suggest all programmer to start using language files in some kind of manner, such as the array format, files location, and etc, so it can be edited later on.

        Tell me what you guys think?
          Wendy Novianto
          [font=Verdana]PT DJAMOER Technology Media
          [font=Verdana]Xituz Media
          • 6726
          • 7,075 Posts
          Once again I am no coder, but you make me think about one thing : we sure need to have a way to localize snippets, plugins and modules...

          Could those be using arrays as well for language strings ? Would that allow for using the kind of interface I mentionned to localize them ?
            .: COO - Commerce Guys - Community Driven Innovation :.


            MODx est l'outil id
            • 32241
            • 1,495 Posts
            Quote from: davidm at Feb 15, 2006, 06:00 PM

            Once again I am no coder, but you make me think about one thing : we sure need to have a way to localize snippets, plugins and modules...

            Could those be using arrays as well for language strings ? Would that allow for using the kind of interface I mentionned to localize them ?

            I’ll look further into this tomorow or maybe next week.
            Basically it will be really simple for us to have a script that fetch the language file and generate localization editing for that specific language file, and later it will save the localization back to the file.

            The only thing that we need to do is to make the default standard for each snippets/modules/plugins to have a language folder/files.

            Here is what I have in mind, correct me if you guys don’t agree with me.
            assets/
            |--snippets/
            |  |--snippet_name1/
            |  |  |--lang/
            |  |  |  |--lang.en.inc.php
            |  |  |  |--lang.fr.inc.php
            |  |--snippet_name2/
            |  |  |--lang/
            |  |  |  |--lang.en.inc.php
            |  |  |  |--lang.fr.inc.php
            |--modules/
            |  |--module_name/
            |  |  |--lang/
            |  |  |  |--lang.en.inc.php
            |  |  |  |--lang.fr.inc.php
            |--plugins/
            |  |--plugin_name/
            |  |  |--lang/
            |  |  |  |--lang.en.inc.php
            |  |  |  |--lang.fr.inc.php
            


            So basically, we need to make the module to auto read the directory and display all available languages that can be edited or added. It will also read the default language file for manager, which located under manager folder.
            Everything will run under module.
              Wendy Novianto
              [font=Verdana]PT DJAMOER Technology Media
              [font=Verdana]Xituz Media
              • 7455
              • 2,204 Posts
              sow what wil happen to a snippet that suports this idea used on a multilangual site?
              do we need to ad a option in the snippetcall to choose what language you like the snippet to be shown in?
              that would be a great way just have 1 tv for language selection and link the output to the snippet call

              I think this could be a great idea I also like the on the fly editing in the manager (mabe an option to have a backup made before editing?

              MODx RUlz....

              Dimmy
                follow me on twitter: @dimmy01
                • 28042 ☆ A M B ☆
                • 24,524 Posts
                You would need to have an option to set the language in the snippet call; this would be either to a default language file or would be set via a snippet or plugin determining the langauage the user wants in some manner (cookie, URL, location in the document tree).
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 10487 MODX Staff
                  • 1,535 Posts
                  Wendy, this is a great idea! cool

                  I would love to see some form of easily-implemented localisation settings, especially if every snippet/module/plugin could run off the same system.

                  On all of my contributions (and there’s a few more in the pipeline), I get very conscious of hardcoding text (for example form buttons and labels). I’m already reworking the ones I’ve contributed so far to make it a bit easier to change the text but a common format would be cool! smiley (and a few examples wink )

                  Cheers, Garry
                    Garry Nutting
                    Senior Developer
                    MODX, LLC

                    Email: [email protected]
                    Twitter: @garryn
                    Web: modx.com
                    • 32241
                    • 1,495 Posts
                    Quote from: sottwell at Feb 16, 2006, 03:02 AM

                    You would need to have an option to set the language in the snippet call; this would be either to a default language file or would be set via a snippet or plugin determining the langauage the user wants in some manner (cookie, URL, location in the document tree).

                    The answer that Susan stated might be the best possible solution. Right now, all we need s just to standardize it. I’ll see what I can do, I try to build a simple prototype for this, hopefully I can release it today.

                    Here is the plan.
                    1. Create a library class for Localization. This class will be the workhorse for the whole localization thing, which include detecting user/browser language, administering language file, determining the existency of language file to be used by snippets/plugins/modules (if there is no specific language file, it will use default).
                    2. Create a plugin to use the above class to detect user language, and set a session/cookie base on that.
                    3. Create an example snippet which will use the localization library. Snippet will at least have 2 optional parameters; 1st to choose default language, if none being set, it will automatically use en (english), and 2nd to determine whether the default language will be changeable or not, if set to no, even the plugin set a new language for the user, the snippet will still use the default language.

                    Please comment on this thing, all your suggestions and comments are welcome, for us to achieve the same standardiziation for the next resourcess releases.

                    Sinserely,
                      Wendy Novianto
                      [font=Verdana]PT DJAMOER Technology Media
                      [font=Verdana]Xituz Media
                      • 32241
                      • 1,495 Posts
                      Ok guys, here is a really superfast prorotype code for standardizing the localization. I’m not planning to do it now though, cause we are in the need of having an implementation of small-mid size Shopping Cart for MODx. So for now, I will work on that part for a while, before I’ll be able to touch this thing again. Garryn, if you’re interested, you can go ahead and take over the project wink

                      Filename: local.class.inc.php
                      Description: To allow the use of this class inside snippets/plugins/modules
                      <?php
                      //
                      // RESPONSIBLE WITH SNIPPETS/PLUGINS/MODULES LOCALIZATION
                      //
                      
                      include_once('userlang.class.inc.php');
                      
                      class local {
                      	// Declaring private variables
                      	var $langPath
                      	var $langDefault;
                      	var $langFix;
                      	var $langData; // Containing all the array for the local translation
                      	// Constant
                      	var $langList;
                      	
                      	// Constructor
                      	function local($langPath, $langDefault='en', $langFix=false) {
                      		// Setting up default value for private variables
                      		$this->langPath = $langPath
                      		$this->langDefault = $langDefault;
                      		$this->langFix = $langFix;
                      		// All available language option1`
                      		$this->langList['en'] = 'english';
                      		$this->langList['fr'] = 'french';
                      		// Include the language file
                      		$this->includeLanguageFile($this->getCurrentLanguage());
                      	}
                      	
                      	//
                      	// Localization API
                      	//
                      	
                      	// Get desired language data
                      	function getLang($text) {
                      		if(isset($this->langData[$text])) return $this->langData[$text];
                      		else return '';
                      	}
                      	
                      	// To get the current language code
                      	function getCurrentLanguage() {
                      		if(!$this->langFix && isset($_SESSION['currLang']))
                      			return $_SESSION['currLang'];
                      		else if(!$this->langFix && isset($_GET['lang']))
                      			return $_GET['lang'];
                      		else
                      			return $this->langDefault;
                      	}
                      	
                      	// To include the language file
                      	function includeLanguageFile($langCode) {
                      		$currLangFile = rtrim($langPath, '/').'/'.$langList[$langCode].'.inc.php';
                      		$defaultLangFile = rtrim($langPath, '/').'/'.$langList[$langDefault].'.inc.php';
                      		include_once($defaultLangFile);
                      		if(file_exists($currLangFile))
                      			include_once($currLangFile);
                      		$this->langData = $_lang;
                      	}
                      }
                      ?>
                      


                      Filename: userlang.class.inc.php
                      Description: To be used by both local.class.inc.php and plugin
                      <?php
                      //
                      // TO BE USED BY PLUGIN TO DETECT THE RIGHT LANGUAGE
                      // IT WILL BE CALLED AUTOMATICALLY BY SNIPPET, IF IT"S NOT BEING SETUP ON PLUGIN
                      //
                      
                      class userLang {
                      	// Get current user browser language
                      	function getBrowserLang() {
                      		//
                      		// I WILL NEED TO IMPLEMENT BROWSER DETECTION AND APPLY THEM TO SESSION
                      		//
                      		return $lang;
                      	}
                      	
                      	// Detect the right language to be use
                      	function detectLanguage() {
                      		if(isset($_GET['lang']))
                      			$_SESSION['currLang'] = $_GET['lang'];
                      		else if(!isset($_SESSION['currLang'])
                      			$_SESSION['currLang'] = $this->getBrowserLang();
                      	}
                      }
                      ?>
                      


                      Filename: localadmin.class.inc.php
                      Description: To be the class for creating an admin interface for languages files. It’s adviseable to make it flexible with the current templating library called chunkTpl, and allow the use of this class inside snippet, which on the snippet, it will allow to personalize the snippet, so that it’s allowed to change certain language only on certain resources. I also want this to be use on module to be the major area for editing all the available language translations for manager and resources.
                      <?php
                      //
                      // TRY TO KEEP THE CODE FLEXIBLE
                      // USE chunkTpl for flexible templating
                      //
                      ?>
                      


                      Filename: DetectLang.plugin.tpl
                      Description: A plugin to detect the current user language
                      //
                      // BASICALLY IT WILL IMPLEMENT userlang.class.inc.php CLASS
                      //
                      


                      Filename: SiteLang.plugin.tpl
                      Description: Plugin code to allow auto selector of what’s the current template, and it will fetch the right language file located inside the assets/templates/template_name_folder/lang/ folder, which allow specific template to have its own translation as well. So it will auto fetch the language file.
                      //
                      // USE local.class.inc.php FOR PARSING THE LANGUAGE FILE
                      // SET PLACEHOLDER PREFIXED WITH 'lang_' TO BE USED INSIDE TEMPLATE
                      //
                      


                      Filename: LangAdmin.module.tpl
                      Description: Module code to allow administering all the available translation in admin and resources (snippet, plugin, module, template)
                      //
                      // IMPLEMENT localadmin.class.inc.php CLASS WITH NO RESTRICTION
                      //
                      


                      Filename: LangAdmin.snippet.tpl
                      Description: Snippet code to allow administering translations file with a few restriction that can be set during snippet calling.’
                      //
                      // IMPLEMENT localadmin.class.inc.php CLASS WITH A FEW RESTRICTION
                      //
                      


                      Ehmm, I hope it’s clear to some of you guys, any input or modification will be awesome, if you guys interested in continuing the project.

                      Sincerely,
                        Wendy Novianto
                        [font=Verdana]PT DJAMOER Technology Media
                        [font=Verdana]Xituz Media