diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-10-20 15:22:37 +0300 |
---|---|---|
committer | Lukas Reschke <lukas@statuscode.ch> | 2016-10-20 15:22:37 +0300 |
commit | 808b0b45ec40e56b4d2e77910eef3963f44ffc60 (patch) | |
tree | 714e4db793a3733aeba8871bc9c9f9113e020758 /l10n.php | |
parent | aa4ef66be65155ec950298b735fd7029ac8975b9 (diff) |
Inject page name
Diffstat (limited to 'l10n.php')
-rw-r--r-- | l10n.php | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -1,6 +1,13 @@ <?php class L10N { + /** @var string */ + private $pageName; + + public function __construct($pageName) { + $this->pageName = $pageName; + } + private function getCurrentLanguage() { // We detect the current language on the hl parameter if(isset($_GET['hl'])) { @@ -14,7 +21,7 @@ class L10N { } public function t($string) { - $baseTranslationFile = __DIR__ . '/l10n/base/' . get_post()->post_name . '.json'; + $baseTranslationFile = __DIR__ . '/l10n/base/' . $this->pageName . '.json'; if(!file_exists($baseTranslationFile)) { file_put_contents($baseTranslationFile, json_encode([])); } @@ -27,7 +34,7 @@ class L10N { } // Read the translated string - $translationFile = __DIR__ . '/l10n/'.$this->getCurrentLanguage().'/' . get_post()->post_name . '.json'; + $translationFile = __DIR__ . '/l10n/'.$this->getCurrentLanguage().'/' . $this->pageName . '.json'; if(file_exists($translationFile)) { $translations = json_decode(file_get_contents($translationFile), true); if(isset($translations[$string])) { @@ -38,5 +45,3 @@ class L10N { return $string; } } - -$l = new L10N();
\ No newline at end of file |