-
Notifications
You must be signed in to change notification settings - Fork 0
LangBuilder
[category:libraries::language]
[h3]Language Files Builder[/h3]
This utility class eases the process of translation management for CI language files. The goal is to centralize all translated items in one CSV file. This allows to keep a consistent baseline for translated data and to keep track of those who need to be translated (the blank columns) after a huge amount of change/improvement in the multilingual views.
The CSV formatted data could be retrieve through the use of the [url=http://www.codeigniter.com/Wiki/CSVReader]CSVReader[/url]
[h3]Requirements[/h3]
- CI: tested on 1.5.3
- PHP: tested on 5.2.1
[h3]The code[/h3]
[code]<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); /**
-
LangBuilder Class
-
$Id: langbuilder.php 138 2007-05-30 16:05:59Z Pierre-Jean $ -
Build languages files from languages data as needed in the language/
-
sub directories.
-
The following data organization is assumed:
-
Array( -
[0] => Array( -
[line] => Checkout -
[français] => Commander -
[english] => Checkout -
) -
[1] => Array( -
[line] => Remove item -
[français] => Retirer l'article -
[english] => Remove item -
) -
) -
It will produce the following files:
-
<language_directory>/français/generated_lang.php
-
<?php -
$lang['Checkout'] = 'Commander'; -
$lang['Remove item'] = 'Retirer l’rticle'; -
?> -
<language_directory>/english/generated_lang.php
-
<?php -
$lang['Checkout'] = 'Checkout'; -
$lang['Remove item'] = 'Remove item'; -
?> -
@author Pierre-Jean Turpeau
-
@link http://www.codeigniter.com/wiki/LangBuilder */ class LangBuilder {
/**
-
Build the language files from the specified data.
-
@param array
-
@param string
-
@param string
-
@return void */ function build($p_Data, $p_LanguageDirectoryPath, $p_TargetName = 'generated' ) { $CI =& get_instance();
$php = array();
foreach( $p_Data as $item ) { foreach( $item as $lang => $value ) { if( $lang != 'line' ) { // skip the 'line' column if( !isset($php[$lang]) ) { $php[$lang] = ''; }
if( trim($value) != '' ) { $php[$lang] .= "\$lang['".trim($item['line'])."'] = '".preg_replace('/\'/', '’', preg_replace('/"/', '"', trim($value)))."';\n"; } } }}
foreach( $php as $lang => $text ) { $filename = $p_LanguageDirectoryPath.'/'.trim($lang).'/'.$p_TargetName.'_lang.php'; $f = fopen($filename, 'w'); fwrite($f, "<?php\n"); fwrite($f, $text); fwrite($f, "?>\n"); fclose($f); } }
} ?> [/code]
-
- Original author: Derek Jones
- How to extend helpers: See User Guide
- Modified by: Thomas Stapleton (id, classes, selected country option and all option)
- Modified by: Bradley De-Lar (construct, setLayout example)