From 6a690202f0a2554f1c283521d4b71dfb0092d2fa Mon Sep 17 00:00:00 2001 From: BernhardBaumrock Date: Thu, 11 Jan 2024 15:59:08 +0100 Subject: [PATCH 1/2] docs: improve notes and comments --- RockLanguage.module.php | 102 +++++++++++++++++++++++----------------- 1 file changed, 58 insertions(+), 44 deletions(-) diff --git a/RockLanguage.module.php b/RockLanguage.module.php index 77b869e..0c6b63a 100644 --- a/RockLanguage.module.php +++ b/RockLanguage.module.php @@ -1,12 +1,17 @@ - 'RockLanguage', 'version' => '1.0.1', @@ -17,25 +22,28 @@ public static function getModuleInfo() { ]; } - public function init() { + public function init() + { $this->sync(); } /** * Copy file if it is newer */ - public function copyIfNewer($from, $to, $toName) { - if(is_file($to) AND filemtime($from) <= filemtime($to)) return; + public function copyIfNewer($from, $to, $toName) + { + if (is_file($to) and filemtime($from) <= filemtime($to)) return; $this->wire->files->copy($from, $to); $fromName = basename($from); $this->log("Copied $fromName to $toName"); } - public function getCustomCodes() { + public function getCustomCodes() + { $codes = []; - foreach(explode("\n", $this->customCodes ?: '') as $line) { + foreach (explode("\n", $this->customCodes ?: '') as $line) { $parts = explode("=", $line, 2); - if(count($parts)!=2) continue; + if (count($parts) != 2) continue; $codes[$parts[0]] = $parts[1]; } return $codes; @@ -44,33 +52,35 @@ public function getCustomCodes() { /** * @return array */ - public function getLanguageCodes($returnString = false) { - if(!$this->wire->languages) return []; + public function getLanguageCodes($returnString = false) + { + if (!$this->wire->languages) return []; $codes = []; $string = ''; $custom = $this->getCustomCodes(); - foreach($this->wire->languages as $lang) { + foreach ($this->wire->languages as $lang) { $code = strtoupper($lang->name); - if(array_key_exists($lang->name, $custom)) $code = $custom[$lang->name]; + if (array_key_exists($lang->name, $custom)) $code = $custom[$lang->name]; $codes[$lang->id] = $code; $string .= "$lang->name=$code
"; } - if($returnString) return $string; + if ($returnString) return $string; return $codes; } /** * pull translation files from modules to language */ - public function pull() { - foreach($this->getLanguageCodes() as $id=>$code) { + public function pull() + { + foreach ($this->getLanguageCodes() as $id => $code) { // find all language files in site modules $modules = $this->wire->config->paths->siteModules; - $files = glob($modules."*/RockLanguage/$code/site--modules--*.json"); - foreach($files as $moduleFile) { + $files = glob($modules . "*/RockLanguage/$code/site--modules--*.json"); + foreach ($files as $moduleFile) { $name = basename($moduleFile); - $langFile = $this->wire->config->paths->files.$id."/$name"; + $langFile = $this->wire->config->paths->files . $id . "/$name"; $this->copyIfNewer($moduleFile, $langFile, "language $id"); } } @@ -79,20 +89,21 @@ public function pull() { /** * push translation files from language to modules */ - public function push() { - foreach($this->getLanguageCodes() as $id=>$code) { + public function push() + { + foreach ($this->getLanguageCodes() as $id => $code) { // find all language files in language folder - $langpath = $this->wire->config->paths->files.$id."/"; - $files = glob($langpath."site--modules--*.json"); - foreach($files as $langFile) { + $langpath = $this->wire->config->paths->files . $id . "/"; + $files = glob($langpath . "site--modules--*.json"); + foreach ($files as $langFile) { $json = json_decode(file_get_contents($langFile)); $parts = explode("/", $json->file); $module = $parts[2]; $dir = $this->wire->config->paths->siteModules - ."$module/RockLanguage/$code/"; - if(!is_dir($dir)) continue; - $moduleFile = $dir.basename($langFile); + . "$module/RockLanguage/$code/"; + if (!is_dir($dir)) continue; + $moduleFile = $dir . basename($langFile); $this->copyIfNewer($langFile, $moduleFile, "module $module"); } } @@ -101,35 +112,38 @@ public function push() { /** * Sync language files */ - public function sync() { - if(!$this->wire->user->isSuperuser()) return; - if(!$this->wire->config->debug) return; + public function sync() + { + if (!$this->wire->user->isSuperuser()) return; + if (!$this->wire->config->debug) return; $this->pull(); $this->push(); } /** - * Config inputfields - * @param InputfieldWrapper $inputfields - */ - public function getModuleConfigInputfields($inputfields) { + * Config inputfields + * @param InputfieldWrapper $inputfields + */ + public function getModuleConfigInputfields($inputfields) + { + $inputfields->add([ + 'type' => 'markup', + 'label' => 'Available Mappings', + 'value' => $this->getLanguageCodes(true), + 'notes' => 'This field lists all available languages and their folder names that will be used to push/pull translation files to/from. + A foldername **DE** means that translations will be synced to /site/modules/YourModule/RockLanguage/**DE**/yourfile.json; + Sync will only take place if $config->debug=true and user is superuser!', + ]); + $inputfields->add([ 'type' => 'textarea', 'name' => 'customCodes', 'label' => 'Language Code Mapping Overrides', - 'notes' => 'Enter one per line, eg default=DE', + 'notes' => 'Enter one per line. Also see notes in the field above. + Example: default=DE', 'value' => $this->customCodes, ]); - $inputfields->add([ - 'type' => 'markup', - 'label' => 'Available Mappings', - 'value' => $this->getLanguageCodes(true), - 'notes' => 'This field lists all available languages and their folder names that will be used to push/pull translation files to/from.' - ."\nA foldername **DE** means that translations will be synced to /site/modules/YourModule/RockLanguage/**DE**/yourfile.json", - ]); - return $inputfields; } - } From 2b6f2b1b54cd613f0f93efd66e4511ae4f93078f Mon Sep 17 00:00:00 2001 From: BernhardBaumrock Date: Fri, 18 Oct 2024 17:27:32 +0200 Subject: [PATCH 2/2] feat!: bump version --- .github/workflows/main.yml | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..994a499 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,29 @@ +name: Releases +on: + push: + branches: + - main + +jobs: + changelog: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: conventional Changelog Action + id: changelog + uses: TriPSs/conventional-changelog-action@v5 + with: + preset: "conventionalcommits" + github-token: ${{ secrets.github_token }} + git-user-email: "office@baumrock.com" + + - name: create release + uses: actions/create-release@v1 + if: ${{ steps.changelog.outputs.skipped == 'false' }} + env: + GITHUB_TOKEN: ${{ secrets.github_token }} + with: + tag_name: ${{ steps.changelog.outputs.tag }} + release_name: ${{ steps.changelog.outputs.tag }} + body: ${{ steps.changelog.outputs.clean_changelog }}