Skip to content

Instantly share code, notes, and snippets.

@EldonMcGuinness
Last active November 26, 2019 23:21
Show Gist options
  • Save EldonMcGuinness/3fe669595b39043672590cdc77ab8b3c to your computer and use it in GitHub Desktop.
Save EldonMcGuinness/3fe669595b39043672590cdc77ab8b3c to your computer and use it in GitHub Desktop.
Simple localization script
<?php
class Localization {
private $localization_directory = null;
private $language = null;
private $localization_array = null;
private $test_data = '{
"00000000": "Hello",
"00000001": "How Are You"
}';
public function get_string( $id ){
if ( array_key_exists($id, $this->localization_array) ) {
return $this->localization_array[$id];
}else{
return "Missing String";
}
}
// Setup the localization language
public function __construct( $language = 'EN', $directory = './' ){
$this->language = $language;
$this->localization_directory = rtrim($directory, '/');
$this->load_localization_file();
}
private function load_localization_file(){
echo "Reading: $this->localization_directory/$this->language.json\n";
$this->localization_array = json_decode(
//file_get_contents(
// "$this->localization_directory/$this->language.json"
//),
$this->test_data,
$assoc = true
);
}
}
$locale = new Localization( 'ES', './' );
echo ($locale->get_string("00000000")."\n");
echo ($locale->get_string("00000001")."\n");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment