From d1e8fd91dc7414f67e8e02d767f867cfa8ccb077 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Mon, 18 May 2020 19:41:11 +0200 Subject: [PATCH] support locale at application level using package.json --- src/core/BaseApplication.coffee | 8 ++ src/core/gui.coffee | 4 +- src/core/languages/gen.sh | 2 +- src/core/languages/vi_VN.json | 75 +++++++++++++++++++ src/core/languages/vi_VN.json.old | 60 +++++++++++++++ .../extensions/templates/sdk-package.tpl | 3 +- src/packages/Files/package.json | 4 +- 7 files changed, 152 insertions(+), 4 deletions(-) mode change 100644 => 100755 src/core/languages/gen.sh diff --git a/src/core/BaseApplication.coffee b/src/core/BaseApplication.coffee index 0bd854a..e63fbc7 100644 --- a/src/core/BaseApplication.coffee +++ b/src/core/BaseApplication.coffee @@ -46,6 +46,7 @@ class BaseApplication extends this.OS.GUI.BaseModel when "#{@name}-about" then @openDialog "AboutDialog" when "#{@name}-exit" then @trigger "exit" @on "apptitlechange", () => @sysdock.update() + @updateLocale @systemsetting.system.locale @loadScheme() loadScheme: () -> @@ -61,6 +62,13 @@ class BaseApplication extends this.OS.GUI.BaseModel return unless @keycomb[fnk] @keycomb[fnk][c] = f + updateLocale: (name) -> + meta = @meta() + return unless meta and meta.locales + return unless meta.locales[name] + for k, v of meta.locales[name] + @_api.lang[k] = v + shortcut: (fnk, c, e) -> return true unless @keycomb[fnk] return true unless @keycomb[fnk][c] diff --git a/src/core/gui.coffee b/src/core/gui.coffee index a4f5c61..8f59a92 100644 --- a/src/core/gui.coffee +++ b/src/core/gui.coffee @@ -190,7 +190,9 @@ Ant.OS.GUI = dock.get(0).newapp data app.sysdock = dock.get(0) app.appmenu = ($ "[data-id = 'appmenu']", "#syspanel")[0] - app.subscribe "systemlocalechange", (name) -> app.update() + app.subscribe "systemlocalechange", (name) -> + app.updateLocale(name) + app.update() app.subscribe "appregistry", ( m ) -> app.applySetting m.data.m if (m.name is app.name) diff --git a/src/core/languages/gen.sh b/src/core/languages/gen.sh old mode 100644 new mode 100755 index 706d147..e0a391a --- a/src/core/languages/gen.sh +++ b/src/core/languages/gen.sh @@ -20,7 +20,7 @@ ord() { LC_CTYPE=C printf '%d' "'$1" } -grep --include=\*.{coffee} -roh "$1" -e '__("[^"]*"' | while read -r line ; do +grep --include=\*.coffee -roh "$1" -e '__("[^"]*"' | while read -r line ; do SUBSTRING=$(echo $line| cut -d'"' -f 2) if test -f "$2" && [ ! -z "$(grep -F "\"$SUBSTRING\":" "$2")" ] then diff --git a/src/core/languages/vi_VN.json b/src/core/languages/vi_VN.json index 466854a..1524918 100644 --- a/src/core/languages/vi_VN.json +++ b/src/core/languages/vi_VN.json @@ -318,4 +318,79 @@ "Welcome to AntOSDK":"Welcome to AntOSDK", "Your application version is older ({0} < {1})":"Your application version is older ({0} < {1})", "zip file generated in release folder":"zip file generated in release folder" + +, + "Cancels":"Cancels", + "Command Palette":"Command Palette", + "Mount Points":"Mount Points", + "New CodePad extension at":"New CodePad extension at", + "Report":"Report", + "Select extension archive":"Select extension archive", + "System error log":"System error log" + +, + "[^":"[^", + "{0} is not a file":"{0} is not a file", + "Action {0} is unsupported on: {1}":"Action {0} is unsupported on: {1}", + "Application meta data isnt found":"Application meta data isnt found", + "Cannot load extension meta data":"Cannot load extension meta data", + "Cannot load scheme: {0}":"Cannot load scheme: {0}", + "Cannot read folder: {0}":"Cannot read folder: {0}", + "Change language mode":"Change language mode", + "Change theme":"Change theme", + "Command palete":"Command palete", + "Command palette":"Command palette", + "ct:Logout":"ct:Logout", + "ct:Toggle fullscreen":"ct:Toggle fullscreen", + "ct:User: {0}":"ct:User: {0}", + "Current folder is not found":"Current folder is not found", + "Error reported":"Error reported", + "Error saving file {0}: {1}":"Error saving file {0}: {1}", + "Example action":"Example action", + "Extension installed":"Extension installed", + "ExtensionName":"ExtensionName", + "Fail to create: {0}":"Fail to create: {0}", + "Fail to download: {0}":"Fail to download: {0}", + "Fail to publish: {0}":"Fail to publish: {0}", + "Fail to read: {0}":"Fail to read: {0}", + "Fail to rename: {0}":"Fail to rename: {0}", + "Fail to upload: {0}":"Fail to upload: {0}", + "Install extension":"Install extension", + "Invalid library: {0}":"Invalid library: {0}", + "New Extension":"New Extension", + "New project from current folder":"New project from current folder", + "New Project":"New Project", + "No meta-data found":"No meta-data found", + "Open folder":"Open folder", + "Open Folder":"Open Folder", + "Package is generated in release folder":"Package is generated in release folder", + "Please select a day":"Please select a day", + "Please select an item":"Please select an item", + "Please select color":"Please select color", + "Start":"Start", + "The folder is not empty: {0}":"The folder is not empty: {0}", + "Unable to build extension":"Unable to build extension", + "Unable to build project":"Unable to build project", + "Unable to create archive":"Unable to create archive", + "Unable to create extension directories":"Unable to create extension directories", + "Unable to create extension template":"Unable to create extension template", + "Unable to create package archive":"Unable to create package archive", + "Unable to create project directory":"Unable to create project directory", + "Unable to create template files":"Unable to create template files", + "Unable to find action: {0}":"Unable to find action: {0}", + "Unable to find extension: {0}":"Unable to find extension: {0}", + "Unable to install extension":"Unable to install extension", + "unable to load extension: {0}":"unable to load extension: {0}", + "Unable to load libraries":"Unable to load libraries", + "Unable to open: {0}":"Unable to open: {0}", + "Unable to preload extension":"Unable to preload extension", + "Unable to read: {0}":"Unable to read: {0}", + "Unable to read meta-data":"Unable to read meta-data", + "Unable to report error: {0}":"Unable to report error: {0}", + "Unable to run extension":"Unable to run extension", + "Unable to run project":"Unable to run project", + "Unable to save file: {0}":"Unable to save file: {0}", + "Value":"Value", + "Verifying: {0}":"Verifying: {0}", + "VFS unknown handle: {0}":"VFS unknown handle: {0}" } diff --git a/src/core/languages/vi_VN.json.old b/src/core/languages/vi_VN.json.old index c946656..73c6097 100644 --- a/src/core/languages/vi_VN.json.old +++ b/src/core/languages/vi_VN.json.old @@ -267,4 +267,64 @@ , "Graph editor":"Graph editor", "Render":"Render" + +, + "add {0} to zip":"add {0} to zip", + "Add files to build target":"Add files to build target", + "and unsaved project":"and unsaved project", + "Build and Run":"Build and Run", + "Build":"Build", + "Build done":"Build done", + "Build Options":"Build Options", + "Build release":"Build release", + "Cannot create file: {0}":"Cannot create file: {0}", + "Cannot save project: {0}":"Cannot save project: {0}", + "Cannot save the zip file {0} : {1}":"Cannot save the zip file {0} : {1}", + "Coffees":"Coffees", + "Compiled successful":"Compiled successful", + "Copied {0} -> {1}":"Copied {0} -> {1}", + "Copied files":"Copied files", + "Created directory: {0}":"Created directory: {0}", + "Created file: {0}":"Created file: {0}", + "Css":"Css", + "Error when create directory: {0}":"Error when create directory: {0}", + "Generated {0}":"Generated {0}", + "Hide":"Hide", + "Ignore: {0} unsaved files {1}?":"Ignore: {0} unsaved files {1}?", + "Ignore unsaved project ?":"Ignore unsaved project ?", + "Installing...":"Installing...", + "Javascripts":"Javascripts", + "Metadata found...":"Metadata found...", + "New Project at":"New Project at", + "New project":"New project", + "Opening {0}":"Opening {0}", + "Open project":"Open project", + "Open Project":"Open Project", + "Output":"Output", + "Please select {0} only":"Please select {0} only", + "Please select a file/fofler":"Please select a file/fofler", + "Preparing for release":"Preparing for release", + "ProjectName":"ProjectName", + "Project":"Project", + "project saved":"project saved", + "Running {0}...":"Running {0}...", + "Select a file":"Select a file", + "Show":"Show", + "Uninstall: {0}?":"Uninstall: {0}?", + "Unsaved project":"Unsaved project", + "Update":"Update", + "Verifying {0}":"Verifying {0}", + "Version string is in invalid format: {0}":"Version string is in invalid format: {0}", + "Welcome to AntOSDK":"Welcome to AntOSDK", + "Your application version is older ({0} < {1})":"Your application version is older ({0} < {1})", + "zip file generated in release folder":"zip file generated in release folder" + +, + "Cancels":"Cancels", + "Command Palette":"Command Palette", + "Mount Points":"Mount Points", + "New CodePad extension at":"New CodePad extension at", + "Report":"Report", + "Select extension archive":"Select extension archive", + "System error log":"System error log" } diff --git a/src/packages/CodePad/coffees/extensions/templates/sdk-package.tpl b/src/packages/CodePad/coffees/extensions/templates/sdk-package.tpl index 8be5f63..357c70d 100644 --- a/src/packages/CodePad/coffees/extensions/templates/sdk-package.tpl +++ b/src/packages/CodePad/coffees/extensions/templates/sdk-package.tpl @@ -9,5 +9,6 @@ "version":"0.0.1-a", "category":"Other", "iconclass":"fa fa-adn", - "mimes":["none"] + "mimes":["none"], + "locale": {} } \ No newline at end of file diff --git a/src/packages/Files/package.json b/src/packages/Files/package.json index 5d53b58..94c4808 100644 --- a/src/packages/Files/package.json +++ b/src/packages/Files/package.json @@ -9,5 +9,7 @@ "version":"0.0.2-a", "category":"System", "iconclass":"fa fa-hdd-o", - "mimes":["dir"] + "mimes":["dir"], + "locales": { + } } \ No newline at end of file