From 93f3707c149a0a71f35aaabf12309f71a5bd944e Mon Sep 17 00:00:00 2001 From: nutti Date: Sat, 25 Nov 2017 16:47:46 +0900 Subject: [PATCH] Add: Support Multi-Language (#14) --- README.md | 1 + .../html/partials/addon-info/buttons.html | 8 +-- .../html/partials/addon-info/github.html | 2 +- .../html/partials/addon-info/installed.html | 2 +- .../html/partials/customdir-list-popup.html | 2 +- src/client/html/partials/error-popup.html | 2 +- src/client/html/partials/footer.html | 8 ++- src/client/html/partials/header.html | 6 +-- .../html/partials/ignore-list-popup.html | 2 +- src/client/html/partials/menu.html | 10 ++-- .../html/partials/migrate-addon-popup.html | 2 +- src/client/js/app.js | 17 ++++++ src/client/js/task.js | 5 +- src/client/sass/lib/_variables.scss | 2 +- src/client/sass/modules/_footer.scss | 7 +++ src/lib/js/blam-translations.js | 54 +++++++++++++++++++ src/lib/js/lang/lang-es.js | 39 ++++++++++++++ src/lib/js/task.js | 6 +-- 18 files changed, 149 insertions(+), 26 deletions(-) create mode 100644 src/lib/js/blam-translations.js create mode 100644 src/lib/js/lang/lang-es.js diff --git a/README.md b/README.md index 84f802b..dbef13d 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ You can install/uninstall/update all add-on's released on GitHub with this appli |Version|Download URL| |---|---| +|1.1|[Download](https://github.com/nutti/Blender-Add-on-Manager/releases/tag/v1.1)| |1.0|[Download](https://github.com/nutti/Blender-Add-on-Manager/releases/tag/v1.0)| |0.3|[Download](https://github.com/nutti/Blender-Add-on-Manager/releases/tag/v0.3)| |0.2|[Download](https://github.com/nutti/Blender-Add-on-Manager/releases/tag/v0.2)| diff --git a/src/client/html/partials/addon-info/buttons.html b/src/client/html/partials/addon-info/buttons.html index 1c9e4e2..d14a6db 100644 --- a/src/client/html/partials/addon-info/buttons.html +++ b/src/client/html/partials/addon-info/buttons.html @@ -1,20 +1,20 @@
- Install + {{blamTranslate('Install');}}
- Update + {{blamTranslate('Update');}}
- Remove + {{blamTranslate('Remove');}}
diff --git a/src/client/html/partials/addon-info/github.html b/src/client/html/partials/addon-info/github.html index 31ea9e6..7a4203f 100644 --- a/src/client/html/partials/addon-info/github.html +++ b/src/client/html/partials/addon-info/github.html @@ -15,7 +15,7 @@
- {{blStr('description', addonStatus[key].github.bl_info.description);}} + {{blamTranslate(blStr('description', addonStatus[key].github.bl_info.description));}}
{{blStr('author', addonStatus[key].github.bl_info.author);}} diff --git a/src/client/html/partials/addon-info/installed.html b/src/client/html/partials/addon-info/installed.html index 70b2013..5fbd696 100644 --- a/src/client/html/partials/addon-info/installed.html +++ b/src/client/html/partials/addon-info/installed.html @@ -15,7 +15,7 @@
- {{blStr('description', addonStatus[key].installed[targetDir].bl_info.description);}} + {{blamTranslate(blStr('description', addonStatus[key].installed[targetDir].bl_info.description));}}
{{blStr('author', addonStatus[key].installed[targetDir].bl_info.author);}} diff --git a/src/client/html/partials/customdir-list-popup.html b/src/client/html/partials/customdir-list-popup.html index 4e3112e..77d0e27 100644 --- a/src/client/html/partials/customdir-list-popup.html +++ b/src/client/html/partials/customdir-list-popup.html @@ -59,7 +59,7 @@

Add New Custom Directory

- Close + {{blamTranslate('Close');}}
diff --git a/src/client/html/partials/error-popup.html b/src/client/html/partials/error-popup.html index e237886..e42514c 100644 --- a/src/client/html/partials/error-popup.html +++ b/src/client/html/partials/error-popup.html @@ -10,7 +10,7 @@

{{ errMsg }}

- Close + {{blamTranslate('Close');}}
diff --git a/src/client/html/partials/footer.html b/src/client/html/partials/footer.html index 724739c..87c717f 100644 --- a/src/client/html/partials/footer.html +++ b/src/client/html/partials/footer.html @@ -1,8 +1,14 @@ +
+
+ +
+
- {{ task.progress }} + {{ task.progress }} .
diff --git a/src/client/html/partials/header.html b/src/client/html/partials/header.html index 998ed25..39c92be 100644 --- a/src/client/html/partials/header.html +++ b/src/client/html/partials/header.html @@ -34,16 +34,16 @@
-
-
+
- +
diff --git a/src/client/html/partials/ignore-list-popup.html b/src/client/html/partials/ignore-list-popup.html index 6984804..9994c5c 100644 --- a/src/client/html/partials/ignore-list-popup.html +++ b/src/client/html/partials/ignore-list-popup.html @@ -32,7 +32,7 @@

Ignored Add-on List

- Close + {{blamTranslate('Close');}}
diff --git a/src/client/html/partials/menu.html b/src/client/html/partials/menu.html index 9e051c5..7df3969 100644 --- a/src/client/html/partials/menu.html +++ b/src/client/html/partials/menu.html @@ -1,23 +1,23 @@
diff --git a/src/client/html/partials/migrate-addon-popup.html b/src/client/html/partials/migrate-addon-popup.html index 91b506b..7cb86b1 100644 --- a/src/client/html/partials/migrate-addon-popup.html +++ b/src/client/html/partials/migrate-addon-popup.html @@ -31,7 +31,7 @@

Target Version

- Close + {{blamTranslate('Close');}}
diff --git a/src/client/js/app.js b/src/client/js/app.js index fdb24b3..fb447ca 100755 --- a/src/client/js/app.js +++ b/src/client/js/app.js @@ -18,6 +18,8 @@ import BlamFavorite from 'blam-favorite'; const blamFavorite = new BlamFavorite(); import BlamIgnore from 'blam-ignore'; const blamIgnore = new BlamIgnore(); +import BlamTranslations from 'blam-translations'; +const blamTranslations = new BlamTranslations(); import TaskMgr from 'task'; const taskMgr = new TaskMgr(); import Logger from 'logger'; @@ -60,6 +62,21 @@ app.controller('MainController', function ($scope, $timeout) { $scope.blVerSelect = $scope.blVerList[0]; $scope.showBlVerSelect = true; + $scope.langList = ['Language:']; + Array.prototype.push.apply($scope.langList, blamTranslations.supportedLanguages()); + $scope.langSelect = 'Language:'; + blamTranslations.setLanguage('Default (English)'); + + $scope.blamTranslate = (key) => { + return blamTranslations.translate(key); + }; + + $scope.onLangSelectorChanged = () => { + if ($scope.langSelect != 'Language:') { + blamTranslations.setLanguage($scope.langSelect); + } + }; + $scope.addonOrderItemList = [ {name: 'Sort:', value: ''}, {name: 'Add-on Name', value: 'ADDON_NAME'}, diff --git a/src/client/js/task.js b/src/client/js/task.js index dd88499..b8caa88 100644 --- a/src/client/js/task.js +++ b/src/client/js/task.js @@ -16,7 +16,7 @@ function updateTask($scope) { setTimeout(function () { $scope.task = { - 'progress': taskMgr.genProgressString(), + 'progress': taskMgr.genProgressString($scope.blamTranslate), 'progressRate': taskMgr.getCurTaskProgressRate() }; $scope.$apply(); @@ -28,7 +28,7 @@ function completeTask($scope, addon) advanceProgressAndUpdate($scope); setTimeout(function () { $scope.task = { - 'progress': taskMgr.genProgressString() + " '" + addon + "'", + 'progress': taskMgr.genProgressString($scope.blamTranslate) + " '" + addon + "'", 'progressRate': 1.0 }; $scope.$apply(); @@ -73,4 +73,3 @@ taskMgr.addItems( ] ) taskMgr.setCompletionString('UPDATE', 'Updated Add-on'); - diff --git a/src/client/sass/lib/_variables.scss b/src/client/sass/lib/_variables.scss index 414246a..91095b3 100644 --- a/src/client/sass/lib/_variables.scss +++ b/src/client/sass/lib/_variables.scss @@ -21,7 +21,7 @@ $selectbox-bgcolor: $button-bgcolor; $selectbox-hover-bgcolor: $button-hover-bgcolor; $header-height: 5.0rem; -$footer-height: 3.0rem; +$footer-height: 3.5rem; $progressbar-color: #333366; $progressbar-complete-color: $progressbar-color + #777799; diff --git a/src/client/sass/modules/_footer.scss b/src/client/sass/modules/_footer.scss index 7c1135b..5a81736 100644 --- a/src/client/sass/modules/_footer.scss +++ b/src/client/sass/modules/_footer.scss @@ -5,12 +5,19 @@ width: 100%; height: $footer-height; background-color: $footer-bgcolor; + .language-panel { + @include selectbox(80%); + width: 20%; + padding-left: 0.5rem; + display: inline-block; + } .progress-panel { width: 70%; height: $footer-height - 0.8rem; margin-left: auto; margin-right: auto; padding-top: 0.8rem; + display: inline-block; .progress { width: 80%; margin-left: auto; diff --git a/src/lib/js/blam-translations.js b/src/lib/js/blam-translations.js new file mode 100644 index 0000000..f385bcf --- /dev/null +++ b/src/lib/js/blam-translations.js @@ -0,0 +1,54 @@ +'use strict'; + +// external modules +import * as LangES from 'lang/lang-es'; + +// own modules +import Logger from 'logger'; +const logger = new Logger(); + +export default class BlamTranslations +{ + constructor() { + this['dict'] = { "Default (English)": {} }; + this['currentLang'] = "Default (English)"; + + this._buildDict(); + } + + _buildDict() { + for (let key in LangES.langESDict) { + this['dict'][key] = LangES.langESDict[key]; + } + } + + supportedLanguages() { + let langs = [] + for (let key in this['dict']) { + langs.push(key); + } + return langs; + } + + setLanguage(lang) { + let supported = this.supportedLanguages(); + for (let i = 0; i < supported.length; ++i) { + if (supported[i] == lang) { + this['currentLang'] = lang; + return true; + } + } + + return false; // not supported + } + + translate(key) { + let lang = this['currentLang']; + + if (this['dict'][lang][key] === undefined) { + return key; + } + + return this['dict'][lang][key]; + } +} diff --git a/src/lib/js/lang/lang-es.js b/src/lib/js/lang/lang-es.js new file mode 100644 index 0000000..152c766 --- /dev/null +++ b/src/lib/js/lang/lang-es.js @@ -0,0 +1,39 @@ +export const langESDict = { + "Spanish": { + "Version": "Versión", + "Addon List": "Lista de Añadidos", + "Installed": "Instalado", + "Update": "Actualizar", + "Category": "Categoría", + "All": "Todo", + "3D View": "Vista 3D", + "Add Curve": "Añadir Curva", + "Add Mesh": "Añadir Malla", + "Animation": "Animación", + "Development": "Desarrollo", + "Game Engine": "Motor de Juegos", + "Import-Export": "Importar-Exportar", + "Mesh": "Malla", + "Node": "Nodo", + "Object": "Objeto", + "Paint": "Pintar", + "Pie Menu": "Menú Circular", + "Render": "Renderizar", + "Rigging": "Rigging", + "System": "Sistema", + "UI": "Interfaz", + "Sort:": "Ordenar:", + "Add-on Name": "Nombre de Añadido", + "Author": "Autor", + "Ascend": "Ascendente", + "Descend": "Descendente", + "(No Description)": "(Sin Descripción)", + "Link": "Enlace", + "Install": "Instalar", + "Remove": "Eliminar", + "Downloading Add-on ...": "Descargando Añadido", + "Installed Add-on": "Añadido Instalado", + "Deleted Add-on": "Añadido Borrado", + "Close": "Cerrar" + } +}; diff --git a/src/lib/js/task.js b/src/lib/js/task.js index f26ffcc..effe1ef 100755 --- a/src/lib/js/task.js +++ b/src/lib/js/task.js @@ -86,16 +86,16 @@ export default class TaskMgr return (progress + 1) * 1.0 / taskList[curTask]['items'].length; } - genProgressString() { + genProgressString(translator) { let curTask = this['curTask']; let taskList = this['taskList']; if (!taskList[curTask]) { return ""; } if (this.taskInProgress(curTask)) { - return this.getCurTaskItem() + " (" + this.getCurTaskProgress() + "/" + this.getTaskItemTotal() + ")"; + return translator(this.getCurTaskItem()) + " (" + this.getCurTaskProgress() + "/" + this.getTaskItemTotal() + ")"; } else if (this.taskCompleted(curTask)) { - return taskList[curTask]['completion']; + return translator(taskList[curTask]['completion']); } return "";