Skip to content

Instantly share code, notes, and snippets.

@timneutkens
Created April 29, 2016 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timneutkens/19e58a00ff8af4663c6502a1d89990a4 to your computer and use it in GitHub Desktop.
Save timneutkens/19e58a00ff8af4663c6502a1d89990a4 to your computer and use it in GitHub Desktop.
Export specific language directory to csv
<?php
/**
* PHP version 5.4
* @category Export
* @package Language
* @author Tim Neutkens <tim@weprovide.com>
* @license MIT <https://opensource.org/licenses/MIT>
* @link <weprovide.com>
*/
define('ENVIRONMENT', 'production');
/**
* Placeholder for base_url function
*
* @param string $path path part of url
*
* @return string
*/
function base_url($path = '')
{
return '/'.$path;
}
/**
* Placeholder for base_url function
*
* @param string $path path part of url
*
* @return string
*/
function site_url($path = '')
{
return '/'.$path;
}
/**
* Export csv to file location
*
* @param array $data csv data
* @param string $location location to put file
*
* @return string
*/
function export_csv($data = [], $location = '')
{
$file_name = 'export-lang-'.time().'.csv';
$file_path = $location.'/'.$file_name;
$file = @fopen($file_path, 'w');
fprintf($file, chr(0xEF).chr(0xBB).chr(0xBF));
foreach ($data as $key => $value) {
fputcsv($file, [$key, $value]);
}
fclose($file);
return $file_path;
}
/**
* Load language
*
* @param string $path path to language directory.
*
* @return array
*/
function load_language($path = '')
{
// Loop through dutch translations
$files = glob($path.'/*.php');
foreach ($files as $filename) {
include_once $filename;
}
return $lang;
}
$lang = load_language('application/language/dutch');
// Lang gets filled by the above includes
echo export_csv($lang, '/tmp');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment