-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGxLanguageManager.bbj
109 lines (104 loc) · 3.3 KB
/
GxLanguageManager.bbj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
rem package BBjGridExWidget
rem /**
rem * This file is part of the BBjGridExWidget plugin.
rem * (c) Basis Europe <[email protected]>
rem *
rem * For the full copyright and license information, please view the LICENSE
rem * file that was distributed with this source code.
rem */
use ::BBjWidget/BBjWidget.bbj::BBjWidget
use java.util.HashMap
REM /**
REM * GxLanguageManager.bbj
REM *
REM * The language manager will add, remove language files to the grid.
REM *
REM * The grid will query the language manager in every render to get the translation keys.
REM *
REM * <b>Note</b> Changing the language in the language manager will not automatically trigger a grid re-render.
REM *
REM * @author Hyyan Abo Fakher
REM */
class public GxLanguageManager
field public BBjString Language$ = ""
field public HashMap Languages! = new HashMap()
field public HashMap LoadedLanguages! = new HashMap()
rem /**
rem * GxLanguageManager
rem *
rem * Construct a new GxLanguageManager instance
rem */
method public GxLanguageManager()
#add("de_DE","BBjGridExWidget/langs/de_DE.json")
#add("nl_NL","BBjGridExWidget/langs/nl_NL.json")
#add("fr_FR","BBjGridExWidget/langs/fr_FR.json")
methodend
rem /**
rem * Get the selected language
rem *
rem * @return BBjString the selected language if any, otherwise fallback to `stbl("!LOCALE")`
rem */
method public BBjString getLanguage()
locale$ = stbl("!LOCALE")
methodret iff(len(#Language$) > 0 , #Language$ , locale$)
methodend
rem /**
rem * Add Language File
rem * This method can be used for new languages, or to
rem * overrule the default translation file that is shipped
rem * with the grid plugin
rem *
rem * @param BBjString language$ the language key (ex: de_DE)
rem * @param BBjString path$ the language file (JSON file)
rem */
method public void add(BBjString language$ , BBjString path$)
REM TODO: check if file exits
#Languages!.put(language$ , path$)
#LoadedLanguages!.put(language$ , "")
methodend
rem /**
rem * Remove an added language
rem *
rem * @param BBjString language$ the language key (ex: de_DE)
rem */
method public void remove(BBjString language$)
if #Languages!.containsKey(language$)
#Languages!.remove(language$)
FI
if #LoadedLanguages!.containsKey(language$)
#LoadedLanguages!.remove(language$)
FI
methodend
rem /**
rem * Get the language keys
rem *
rem * Get the translation keys as JSON string
rem *
rem * @return BBjString
rem */
method public String getLanguageKeys()
methodret #getLanguageKeys(#getLanguage())
methodend
rem /**
rem * Get the language keys
rem *
rem * Get the translation keys as JSON string
rem *
rem * @return BBjString
rem */
method public String getLanguageKeys(BBjString language$)
content$ = ""
if #LoadedLanguages!.containsKey(language$) then
content$ = #LoadedLanguages!.get(language$)
rem we did not load the language yet
if len(#LoadedLanguages!.get(language$)) = 0 then
ch=unt
open (ch)#Languages!.get(language$)
read record (ch,siz=5512000)content$
close (ch)
#LoadedLanguages!.put(language$ , new String(content$,"UTF-8"))
FI
FI
methodret new String(content$,"UTF-8")
methodend
classend