]> 91.132.146.200 Git - bibliotheca-php.git/commitdiff
i18n key reuse now working. Needed a prefix
authorBanana <mail@bananas-playground.net>
Sat, 20 Apr 2024 09:44:30 +0000 (11:44 +0200)
committerBanana <mail@bananas-playground.net>
Sat, 20 Apr 2024 09:44:30 +0000 (11:44 +0200)
Signed-off-by: Banana <mail@bananas-playground.net>
documentation/tools.md
webclient/i18n/eng.ini
webclient/lib/i18n.class.php
webclient/view/default/tool/tool-gameinfo.html
webclient/view/default/tool/tool-googlebooks.html
webclient/view/default/tool/tool-imdbweb.html
webclient/view/default/tool/tool-musicbrainz.html

index 4af3bf864926da861d3dbc1087930ecc5f7da573..17d34336101b7522c9253d3589b713f2df1614fc 100644 (file)
@@ -7,6 +7,7 @@ and change name, description and action. The other settings can be left as they
 Filenames are `tool-ACTION.html|php`
 A optional configuration file `config/config-ACTION.php`
 A documentation is a must.
+Add needed translation keys into eng.ini as a minimum.
 
 As a base the provided imdbweb parse is already included. It makes it possible to search for a movie within
 https://www.imdb.com and let you pick with information should be saved into the entry.
index 4bffcd0a2c7421e81ad137fa36251f2c9e3f466d..e66616cac0bdde60e4edc8be641b2bd9afc31687 100644 (file)
@@ -114,10 +114,10 @@ managecol.input.combinedsearch.howto = "This could take some time to complete, d
 managecol.input.defaultsearchfield = "Default global search field"
 managecol.input.defaultsort = "Default sort field"
 managecol.input.defaultsortorder = "Default sort order"
-managecol.input.delete = global.delete
+managecol.input.delete = reuse.global.delete
 managecol.input.delete.howto = "Warning: This will delete ALL the data in this collection!"
-managecol.input.description = global.description
-managecol.input.name = global.name
+managecol.input.description = reuse.global.description
+managecol.input.name = reuse.global.name
 managecol.input.name.placeholder = "Unique name. No special chars."
 managecol.input.overwriterights = "Overwrite existing rights"
 managecol.input.overwriterights.howto = "Warning: This will overwrite existing entry rights (user, group, rights) with the ones from the collection!"
@@ -141,9 +141,9 @@ manageentry.message.noTitle = "Entry has no value in title field."
 manageentry.message.viewNewEntry = "View your new entry"
 manageentry.possibleduplicate = "Possible duplicate"
 manageentry.select.bulkedit = "Select bulk edit option"
-manageentry.select.bulkedit.add = global.add
-manageentry.select.bulkedit.clear = global.clear
-manageentry.select.bulkedit.replace = global.replace
+manageentry.select.bulkedit.add = reuse.global.add
+manageentry.select.bulkedit.clear = reuse.global.clear
+manageentry.select.bulkedit.replace = reuse.global.replace
 manageentry.updateentry = "Update an entry in:"
 manageentry.viewentry = "View entry"
 
@@ -157,17 +157,17 @@ managefields.message.provideValidFields = "Please provide valid fields."
 managegroups.addormodify = "Add or modify a group"
 managegroups.availablegroups = "Available groups"
 managegroups.groupmanagement = "Group management"
-managegroups.input.delete = global.delete
+managegroups.input.delete = reuse.global.delete
 managegroups.input.delete.howto = "Warning: Content owned by this group will not be deleted and thus only manageable by admin!<br />Right now don't do this. Only if you are sure there is no usage of this group."
-managegroups.input.description = global.description
-managegroups.input.name = global.name
-managegroups.input.save = global.save
+managegroups.input.description = reuse.global.description
+managegroups.input.name = reuse.global.name
+managegroups.input.save = reuse.global.save
 managegroups.message.couldNotBeCreated = "Group could not be created."
 managegroups.message.couldNotBeDelete = "Group could not be deleted."
 managegroups.message.couldNotBeUpdated = "Group could not be updated. Either wrong input or duplicate group name"
 managegroups.message.missingName = "Provide name and description."
 
-managetags.delete = global.delete
+managetags.delete = reuse.global.delete
 managetags.howto = "The actions are top down. If you choose to move and rename, only move will be executed.<br />Deletion will remove without recover!<br />If you rename and input an existing one a move will be done instead.<br />Tag values are stored how they come and treated that way here (case sensitive). In search they are case insensitive."
 managetags.managetagsin = "Manage Tags in:"
 managetags.message.executionError = "Can not execute given options. See logs for more."
@@ -179,14 +179,14 @@ managetags.user = "Use"
 
 manageuser.addormodify = "Add or modify a user"
 manageuser.availableusers = "Available users"
-manageuser.created = global.created
+manageuser.created = reuse.global.created
 manageuser.groups = "Group(s)"
 manageuser.input.addgroups = "Additional groups"
 manageuser.input.apitoken = "Create API Token"
 manageuser.input.apitoken.current = "Current Token:"
 manageuser.input.apitoken.valid = "Valid until:"
 manageuser.input.canloging = "Can login"
-manageuser.input.delete = global.delete
+manageuser.input.delete = reuse.global.delete
 manageuser.input.delete.howto = "Warning: Content owned by this user will not be deleted and thus only manageable by admin!<br />Better disable the user if there is content."
 manageuser.input.maingroup = "Main group"
 manageuser.message.couldNotBeCreated = "User could not be created."
@@ -202,21 +202,21 @@ message.headline.success = "Success"
 message.headline.warning = "Warning"
 
 menu.manage = "Manage"
-menu.manage.add = global.add
-menu.manage.collections = global.collections
+menu.manage.add = reuse.global.add
+menu.manage.collections = reuse.global.collections
 menu.manage.groups = "Groups"
 menu.manage.profile = "Profile"
-menu.manage.tags = global.tags
+menu.manage.tags = reuse.global.tags
 menu.manage.users = "Users"
-menu.search = global.search
+menu.search = reuse.global.search
 menu.search.advanced = "Advanced"
 menu.search.enter = "Press enter to search"
 menu.search.within = "Search within the default search field"
 menu.show = "Show"
-menu.show.collections = global.collections
+menu.show.collections = reuse.global.collections
 menu.show.dashboard = "Dashboard"
 menu.show.sysinfo = "System Information"
-menu.show.tags = global.tags
+menu.show.tags = reuse.global.tags
 
 pagination.gotopage = "Goto page"
 pagination.next = "next"
@@ -225,8 +225,8 @@ pagination.select.sort.default = "Default"
 pagination.select.sort.latest = "Latest"
 
 profile.input.addgroups = "Additional groups"
-profile.input.apitoken.current = manageuser.input.apitoken.current
-profile.input.apitoken.valid = manageuser.input.apitoken.valid
+profile.input.apitoken.current = reuse.manageuser.input.apitoken.current
+profile.input.apitoken.valid = reuse.manageuser.input.apitoken.valid
 profile.input.createtoken = "Create API Token"
 profile.input.maingroup = "Main group"
 profile.message.couldNotBeUpdated = "Your profile could not be updated."
@@ -234,12 +234,12 @@ profile.yourprofile = "Manage your profile"
 
 sysinfo.headline.sysinfo = "System information"
 sysinfo.th.collection = "Collection"
-sysinfo.th.created = global.created
+sysinfo.th.created = reuse.global.created
 sysinfo.th.dbusage = "DB Usage"
-sysinfo.th.description = global.description
+sysinfo.th.description = reuse.global.description
 sysinfo.th.diskusage = "Disk Usage"
 sysinfo.th.entries = "Entries"
-sysinfo.th.tags = global.tags
+sysinfo.th.tags = reuse.global.tags
 
 sysfield.actors = "Actors"
 sysfield.artist = "Artist"
@@ -275,5 +275,22 @@ sysfield.missingtemplate = "Missing template for:"
 
 tags.headline.tagsfor = "Tags for:"
 
+tool.gameinfo = "This is a collection of websites which provide different kind of information about games."
+tool.googlebooks.save = reuse.global.save
+tool.googlebooks.search = reuse.global.search
+tool.googlebooks.searchIsbn = "Search ISBN"
+tool.googlebooks.select = reuse.global.none
 tool.headline.using = "Using %s with collection: %s"
+tool.imdb.save = reuse.global.save
+tool.imdb.search = reuse.global.search
+tool.imdb.select.none = reuse.global.none
+tool.limitations = "Limitations"
+tool.limitations.override = "Data will be overwritten"
 tool.message.missingFiles = "Required tool files can not be found."
+tool.music.input.albumTitle = "Album/Title"
+tool.music.input.artist = "Artist"
+tool.music.limitations.override = "Data will be overwritten; No wildcardsearch or partial words."
+tool.music.save = reuse.global.save
+tool.music.search = reuse.global.search
+tool.music.select = "Select"
+tool.music.select.none = reuse.global.none
index 4dfeb5667f9ae44808a3a09c63785d386be2bc06..b2f37028dd7cc49952349402ce84ef2761f553d5 100644 (file)
@@ -34,10 +34,21 @@ class I18n {
      */
     private array $_langData = array();
 
+    /**
+     * @var array The fallback lang data.
+     */
+    private array $_langDataFallback = array();
+
     /**
      * Translation constructor.
      */
     public function __construct() {
+        // load fallback
+        $this->_langDataFallback = parse_ini_file(PATH_ABSOLUTE.'/i18n/eng.ini');
+        if(!$this->_langDataFallback) {
+            Summoner::sysLog('[ERROR] Missing fallback language file!');
+        }
+
         if(defined('FRONTEND_LANGUAGE')) {
             $this->_iso3 = FRONTEND_LANGUAGE['iso3'];
             $this->_iso2 = FRONTEND_LANGUAGE['iso2'];
@@ -50,11 +61,7 @@ class I18n {
             }
         }
         else {
-            $_langFile = PATH_ABSOLUTE.'/i18n/'.$this->_iso3.'.ini';
-            $_langData = parse_ini_file($_langFile);
-            if($_langData !== false) {
-                $this->_langData = $_langData;
-            }
+            $this->_langData = $this->_langDataFallback;
         }
     }
 
@@ -72,19 +79,27 @@ class I18n {
      */
     public function t(string $key, mixed $replace=''): string {
         $ret = $key;
+        $_langWorkWith = $this->_langData;
         if(isset($this->_langData[$key])) {
             $ret = $this->_langData[$key];
-            // the value is another key
-            if(!str_contains($ret, '"') && str_contains($ret, ".") && isset($this->_langData[$ret])) {
-                $ret = $this->_langData[$ret];
+        } elseif(!DEBUG && isset($this->_langDataFallback[$key])) {
+            $ret = $this->_langDataFallback[$key];
+            $_langWorkWith = $this->_langDataFallback;
+        }
+
+        // the value is another key
+        if(str_starts_with($ret, "reuse.")) {
+            $_ret = str_replace("reuse.","",$ret);
+            if(isset($_langWorkWith[$_ret])) {
+                $ret = $_langWorkWith[$_ret];
             }
+        }
 
-            if(!empty($replace)) {
-                if(is_array($replace)) {
-                    $ret = vsprintf($ret, $replace);
-                } else {
-                    $ret = sprintf($ret, $replace);
-                }
+        if(!empty($replace)) {
+            if(is_array($replace)) {
+                $ret = vsprintf($ret, $replace);
+            } else {
+                $ret = sprintf($ret, $replace);
             }
         }
         return $ret;
index fc9e7b2d2f2bd3bb5fc535ebb490510c5f4bd0b2..f42f6acb03e36754071c05d2d4b2d190309e8c43 100644 (file)
@@ -1,4 +1,4 @@
-<p>This is a collection of websites which provide different kind of information about games.</p>
+<p><?php echo $I18n->t('tool.gameinfo');?></p>
 <ul>
        <li><a target=_blank href="https://www.mobygames.com/">Moby Games</a> All plattforms</li>
        <li><a target=_blank href="https://www.gametdb.com/">Game TDB</a> Console games</li>
index ef431a165ef4140e058a80ecc46fe4a33c117748..a465e5f6cd5ee50131769f7222d630c3c932f6dd 100644 (file)
@@ -1,9 +1,9 @@
-<p><b>Limitations</b></p>
-<p>Data will be overwritten</p>
+<p><b><?php echo $I18n->t('tool.lomitations'); ?></b></p>
+<p><?php echo $I18n->t('tool.limitations.override'); ?></p>
 
 <form class="uk-form-horizontal uk-margin-small" method="post" enctype="multipart/form-data">
        <div class="uk-margin">
-               <label class="uk-form-label" for="search">Search ISBN</label>
+               <label class="uk-form-label" for="search"><?php echo $I18n->t('tool.googlebooks.searchIsbn'); ?></label>
                <div class="uk-form-controls">
                        <input class="uk-input" id="search" type="text" autocomplete="off"
                               name="fdata[search]"
@@ -12,7 +12,7 @@
                </div>
                <div class="uk-margin">
                        <button class="uk-button uk-button-primary" type="submit" name="submitFormSearch">
-                               Search
+                               <?php echo $I18n->t('tool.googlebooks.search'); ?>
                        </button>
                </div>
        </div>
@@ -35,7 +35,7 @@
        </div>
        <div class="uk-width-1-2@s">
                <select class="uk-select" name="fdata[into][<?php echo $k; ?>]">
-                       <option value="">None</option>
+                       <option value=""><?php echo $I18n->t('tool.googlebooks.select'); ?></option>
                        <?php echo toolMethod_GetTargetSelection($TemplateData['saveToSelection'],$k); ?>
                </select>
        </div>
@@ -47,7 +47,7 @@
 
        <div class="uk-margin">
                <button class="uk-button uk-button-primary" type="submit" name="submitFormSave">
-                       Save
+                       <?php echo $I18n->t('tool.googlebooks.save'); ?>
                </button>
        </div>
 
index 68817c320b36b24214473de224ee1d3ea061c950..c780ebd25d2b5dc323d2c054775303a941d3c2b0 100644 (file)
@@ -1,9 +1,9 @@
-<p><b>Limitations</b></p>
-<p>Data will be overwritten</p>
+<p><b><?php echo $I18n->t('tool.lomitations'); ?></b></p>
+<p><?php echo $I18n->t('tool.limitations.override'); ?></p>
 
 <form class="uk-form-horizontal uk-margin-small" method="post" enctype="multipart/form-data">
        <div class="uk-margin">
-               <label class="uk-form-label" for="search">Search</label>
+               <label class="uk-form-label" for="search"><?php echo $I18n->t('tool.imdb.search'); ?></label>
                <div class="uk-form-controls">
                        <input class="uk-input" id="search" type="text" autocomplete="off"
                                   name="fdata[search]"
@@ -12,7 +12,7 @@
                </div>
                <div class="uk-margin">
                        <button class="uk-button uk-button-primary" type="submit" name="submitFormSearch">
-                               Search
+                               <?php echo $I18n->t('tool.imdb.search'); ?>
                        </button>
                </div>
        </div>
@@ -34,7 +34,7 @@
        </div>
        <div class="uk-width-1-2@s">
                <select class="uk-select" name="fdata[into][<?php echo $k; ?>]">
-                       <option value="">None</option>
+                       <option value=""><?php echo $I18n->t('tool.imdb.select.none'); ?></option>
                        <?php echo toolMethod_GetTargetSelection($TemplateData['saveToSelection'],$k); ?>
                </select>
        </div>
@@ -46,7 +46,7 @@
 
        <div class="uk-margin">
                <button class="uk-button uk-button-primary" type="submit" name="submitFormSave">
-                       Save
+                       <?php echo $I18n->t('tool.imdb.save'); ?>
                </button>
        </div>
 
index eff6d90f406d18894051ae86fb9beca184df1aa6..08d4967e1f91353b19da92478108e03b8c98695e 100644 (file)
@@ -1,9 +1,9 @@
-<p><b>Limitations</b></p>
-<p>Data will be overwritten; No wildcardsearch or partial words.</p>
+<p><b><?php echo $I18n->t('tool.lomitations'); ?></b></p>
+<p><?php echo $I18n->t('tool.music.limitations.override'); ?></p>
 
 <form class="uk-form-horizontal uk-margin-small" method="post" enctype="multipart/form-data">
        <div class="uk-margin">
-               <label class="uk-form-label" for="artist">Artist</label>
+               <label class="uk-form-label" for="artist"><?php echo $I18n->t('tool.music.input.artist'); ?></label>
                <div class="uk-form-controls">
                        <input class="uk-input" id="artist" type="text" autocomplete="off"
                               name="fdata[artist]"
@@ -12,7 +12,7 @@
                </div>
        </div>
        <div class="uk-margin">
-               <label class="uk-form-label" for="album">Album/Title</label>
+               <label class="uk-form-label" for="album"><?php echo $I18n->t('tool.music.input.albumTitle'); ?></label>
                <div class="uk-form-controls">
                        <input class="uk-input" id="album" type="text" autocomplete="off"
                               name="fdata[album]"
@@ -22,7 +22,7 @@
        </div>
        <div class="uk-margin">
                <button class="uk-button uk-button-primary" type="submit" name="submitFormSearch">
-                       Search
+                       <?php echo $I18n->t('tool.music.search'); ?>
                </button>
        </div>
 </form>
@@ -31,7 +31,6 @@
 <form class="uk-form-horizontal uk-margin-small" method="post" enctype="multipart/form-data">
        <div class="uk-margin">
                <div class="uk-form-controls">
-
                        <?php foreach($TemplateData['releases'] as $k=>$v) { ?>
 
                        <label><input class="uk-radio" type="radio" name="fdata[rselect]" value="<?php echo $k; ?>"> <?php echo $v; ?></label><br>
@@ -42,7 +41,7 @@
 
        <div class="uk-margin">
                <button class="uk-button uk-button-primary" type="submit" name="submitFormReleaseSelect">
-                       Select
+                       <?php echo $I18n->t('tool.music.select'); ?>
                </button>
        </div>
 </form>
@@ -62,7 +61,7 @@
        </div>
        <div class="uk-width-1-2@s">
                <select class="uk-select" name="fdata[into][<?php echo $k; ?>]">
-                       <option value="">None</option>
+                       <option value=""><?php echo $I18n->t('tool.music.select.none'); ?></option>
                        <?php echo toolMethod_GetTargetSelection($TemplateData['saveToSelection'],$k); ?>
                </select>
        </div>
@@ -71,7 +70,7 @@
 
        <div class="uk-margin">
                <button class="uk-button uk-button-primary" type="submit" name="submitFormSave">
-                       Save
+                       <?php echo $I18n->t('tool.music.save'); ?>
                </button>
        </div>
 </form>