Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Dynamic_Translator {
- private $language;
- private $translation_array;
- public function __construct( string $language ) {
- $this->language = $language;
- $this->translation_array = array();
- $this->translation_array['fr_FR']['default'] = array(
- 'yes' => 'oui',
- 'no' => 'non',
- 'Oh yes!' => 'Oh oui !',
- //…
- );
- }
- public function translate( string $translation, string $phrase_to_translate, string $domain ) : string {
- if ( isset( $this->translation_array[ $this->laguage ][ $domain ][ $phrase_to_translate ] ) ) {
- return $this->translation_array[ $this->language ][ $domain ][ $phrase_to_translate ];
- } else {
- return $phrase_to_translate;
- }
- }
- }
Add Comment
Please, Sign In to add comment