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
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,