remote5-gui 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index_lang.js CHANGED
@@ -1,3 +1,3 @@
1
1
  'use strict';
2
2
 
3
- module.exports = require('./lib/wlang-0.2.0.js');
3
+ module.exports = require('./lib/wlang-0.2.1.js');
@@ -0,0 +1,227 @@
1
+ /*
2
+ * Remote5 wLanguages - 2023.11.03~
3
+ * Author : Willy.Lee (wiljwilj@hotmail.com)
4
+ */
5
+ // 0.1.1 - 2023.11.03
6
+ // 0.1.3 - 2025.05.05 loading default lang-json
7
+ // 0.1.4 - 2026.02.13 syntex error fixed
8
+ // 0.1.5 - 2026.02.19 add function finding by contrycode
9
+ // 0.2.1 - 2026.02.21 apply npm library. R5.wLang -> wLang
10
+
11
+ export default
12
+ (function(){
13
+ "use strict";
14
+
15
+ var version = "0.2.1";
16
+
17
+ function wl( defaultLang, cb ) {
18
+ var i = this;
19
+ if (typeof defaultLang == "string") {
20
+ var oLang = new XMLHttpRequest();
21
+ oLang.open("GET", defaultLang, true);
22
+ oLang.send();
23
+ oLang.onreadystatechange = e=>{
24
+ if (oLang.readyState == 4 && oLang.status == 200){
25
+ try{
26
+ var json = JSON.parse(oLang.responseText);
27
+ //console.dir(json);
28
+ i.defaultLang = json;
29
+ if (cb) cb();
30
+ }
31
+ catch {
32
+ console.error(defaultLang + " parsing error");
33
+ if (cb) cb();
34
+ }
35
+ }
36
+ else {
37
+ if (cb) cb();
38
+ }
39
+ }
40
+ }
41
+ else {
42
+ i.defaultLang = defaultLang;
43
+ if (cb) cb();
44
+ }
45
+ }
46
+ wl.prototype = {
47
+ From:function(key, section){
48
+ var lang = this.localLang;
49
+ if (lang != null && section != null)
50
+ lang = lang[section];
51
+ if (lang != null && lang[key] != null)
52
+ return lang[key];
53
+ if (this.defaultLang == null)
54
+ return key;
55
+ lang = this.defaultLang;
56
+ if (lang != null && section != null)
57
+ lang = lang[section];
58
+ if (lang != null) {
59
+ if (lang[key] != null)
60
+ return lang[key];
61
+ if (lang[key] !== undefined)
62
+ return key;
63
+ }
64
+ return null;
65
+ },
66
+ load:function(url, cb){
67
+ var i = this;
68
+ i.localLang = null;
69
+ if (typeof url == "string") {
70
+ var oLang = new XMLHttpRequest();
71
+ oLang.open("GET", url, true);
72
+ oLang.send();
73
+ oLang.onreadystatechange = e=>{
74
+ if (oLang.readyState == 4 && oLang.status == 200){
75
+ try{
76
+ var json = JSON.parse(oLang.responseText);
77
+ //console.dir(json);
78
+ i.localLang = json;
79
+ if (cb) cb();
80
+ }
81
+ catch {
82
+ console.error(url + " parsing error");
83
+ if (cb) cb();
84
+ }
85
+ }
86
+ else {
87
+ if (cb) cb();
88
+ }
89
+ }
90
+ }
91
+ else {
92
+ i.defaultLang = url;
93
+ if (cb) cb();
94
+ }
95
+ },
96
+ reset:function(){
97
+ this.localLang = null;
98
+ }
99
+ };
100
+
101
+ function wLang(key, section) {
102
+ for (let idx = wLang._lang_handles.length - 1; idx >= 0; idx--) {
103
+ let v = wLang._lang_handles[idx][1].From(key, section);
104
+ if (v != null)
105
+ return v;
106
+ }
107
+
108
+ return "[["+key+"]]";
109
+ }
110
+ wLang.version = version;
111
+ wLang._lang_handles = [];
112
+ wLang._defaultLocaleCode = "en-US";
113
+ wLang._langCode = "en";
114
+ wLang._countryCode = "US";
115
+ wLang._listLocaleCode = [];
116
+ wLang.LanguageCode = function(){
117
+ return wLang._langCode;
118
+ };
119
+ wLang.CountryCode = function(){
120
+ return wLang._countryCode;
121
+ };
122
+ wLang.LocaleCode = function(){
123
+ return wLang._langCode+"-"+wLang._countryCode;
124
+ };
125
+ wLang.Initialize = function(listLocaleCode, defaultLocaleCode){
126
+ wLang._listLocaleCode = listLocaleCode;
127
+ if (defaultLocaleCode != null) {
128
+ wLang._lang_handles = [];
129
+ wLang._defaultLocaleCode = defaultLocaleCode;
130
+ let lc = defaultLocaleCode.split('-');
131
+ wLang._langCode = lc[0];
132
+ wLang._countryCode = lc[1];
133
+ }
134
+ };
135
+ wLang.nearLocaleCodeBrower = function(list){
136
+ var userLang = navigator.language || navigator.userLanguage;
137
+ if (userLang == null || userLang == "")
138
+ return null;
139
+ return this.nearLocaleCode(list, userLang);
140
+ };
141
+ wLang.nearLocaleCode = function(list, userLang){
142
+ for (let l in list) {
143
+ if (list[l] == userLang)
144
+ return userLang;
145
+ }
146
+ var lang = userLang.split('-')[0];
147
+ for (let l in list) {
148
+ if (list[l].split('-')[0] == lang)
149
+ return list[l];
150
+ }
151
+ var contry = userLang.split('-')[1];
152
+ for (let l in list) {
153
+ if (list[l].split('-')[1] == contry)
154
+ return list[l];
155
+ }
156
+ return null;
157
+ };
158
+ wLang.matchLocaleCode = function(locale_code){
159
+ let locale = this.nearLocaleCode(wLang._listLocaleCode, locale_code);
160
+ if (locale !== null)
161
+ return locale;
162
+ return this._defaultLocaleCode;
163
+ };
164
+ wLang.Locale = function(locale_code, cb){
165
+ let locale_code_matched = this.matchLocaleCode(locale_code);
166
+ if (locale_code_matched.localeCompare(locale_code) != 0) {
167
+ //R5.Trace("wLang().Locale - "+locale_code+" => "+locale_code_matched);
168
+ locale_code = locale_code_matched;
169
+ }
170
+ else {
171
+ //R5.Trace("wLang().Locale - "+locale_code);
172
+ }
173
+ if (this._defaultLocaleCode.localeCompare(locale_code) == 0) {
174
+ this._lang_handles.forEach(o=>{o[1].reset()});
175
+ if (cb != null) cb();
176
+ }
177
+ else if (locale_code.localeCompare(this._langCode+"-"+this._countryCode) != 0) {
178
+ this._lang_handles.forEach(o=>{
179
+ o[1].load(o[0]+locale_code+".json", cb);
180
+ })
181
+ }
182
+ this._langCode = locale_code.substr(0, 2);
183
+ this._countryCode = locale_code.substr(3);
184
+ };
185
+ wLang.Add = function(prefix, cb, json){
186
+ let lang;
187
+ if (this._defaultLocaleCode.localeCompare(this._langCode+"-"+this._countryCode) == 0) {
188
+ lang = (json == null) ?
189
+ new wl(prefix+this._defaultLocaleCode+".json", cb) :
190
+ new wl(json, cb);
191
+ }
192
+ else {
193
+ lang = (json == null) ?
194
+ new wl(prefix+this._defaultLocaleCode+".json") :
195
+ new wl(json);
196
+ lang.load(prefix+this._langCode+"-"+this._countryCode+".json", cb);
197
+ }
198
+ this._lang_handles.push([prefix,lang]);
199
+ return lang;
200
+ };
201
+ wLang.Remove = function(handle){
202
+ let idx = this._lang_handles.length;
203
+ for (--idx; idx >= 0; idx--) {
204
+ if (Object.is(this._lang_handles[idx][1], handle))
205
+ this._lang_handles.splice(idx, 1);
206
+ }
207
+ };
208
+
209
+ /*
210
+ // text align
211
+ var s_language_right_align = {
212
+ ar:true
213
+ };
214
+ var s_langRightAlign = false;
215
+ s_langRightAlign = s_language_right_align[langcode] == true;
216
+
217
+ Lang.isRightAlign = e=>{
218
+ return false;
219
+ };
220
+ */
221
+
222
+ if (typeof module == 'undefined') {
223
+ window.wLang = wLang;
224
+ }
225
+
226
+ return wLang;
227
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remote5-gui",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Remote5 GUI package.",
5
5
  "main": "./index.js",
6
6
  "license": "MIT",