Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow changing the grid language (#128)
- Loading branch information
Showing
16 changed files
with
62,525 additions
and
44,639 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use ::BBjWidget/BBjWidget.bbj::BBjWidget | ||
use java.util.HashMap | ||
REM /** | ||
REM * BBjGridExWidgetLanguageManager.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 trigger automatically a grid rerender. | ||
REM * | ||
REM * @author Hyyan Abo Fakher | ||
REM */ | ||
class public BBjGridExWidgetLanguageManager | ||
|
||
field public BBjString Language$ = "" | ||
field public HashMap Languages! = new HashMap() | ||
field public HashMap LoadedLanguages! = new HashMap() | ||
rem /** | ||
rem * BBjGridExWidgetLanguageManager | ||
rem * | ||
rem * Construct a new BBjGridExWidgetLanguageManager instance | ||
rem */ | ||
method public BBjGridExWidgetLanguageManager() | ||
#add("de_DE","BBjGridExWidget/langs/de_DE.json") | ||
#add("nl_NL","BBjGridExWidget/langs/nl_NL.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 languge 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 languge 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 BBjString 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 BBjString 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$ , content$) | ||
FI | ||
FI | ||
|
||
methodret content$ | ||
methodend | ||
|
||
classend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
rem /** | ||
rem * Language Demo | ||
rem * | ||
rem * The demo demonstrates working with the grid Language manager to add new languages | ||
rem * or change the current grid language. | ||
rem * | ||
REM * @author Hyyan Abo Fakher | ||
rem */ | ||
|
||
use ::BBjGridExWidget/BBjGridExWidget.bbj::BBjGridExWidget | ||
use com.basiscomponents.bc.SqlQueryBC | ||
|
||
? 'HIDE' | ||
|
||
REM By default the grid will use stbl("!LOCALE") to get the default language | ||
REM Changing this setting will force the grid to use the defined language unless the | ||
REM default's grid language is set direclty using `grid!.getLanguageManager().setLangauge("LANG")` | ||
|
||
declare auto BBjTopLevelWindow wnd! | ||
declare auto BBjListButton lb_languages! | ||
declare BBjGridExWidget grid! | ||
declare BBjVector languages! | ||
|
||
REM Define a list of supported languages | ||
languages! = new BBjVector() | ||
languages!.insertItem(0,"") | ||
languages!.insertItem(1,"de_DE") | ||
languages!.insertItem(2,"nl_NL") | ||
languages!.insertItem(3,"de_SL"); rem Just a demo language file. | ||
|
||
wnd! = BBjAPI().openSysGui("X0").addWindow(10,10,900,600,"BBj Grid Language Demo") | ||
wnd!.setCallback(BBjAPI.ON_CLOSE,"byebye") | ||
wnd!.setCallback(BBjAPI.ON_RESIZE,"resize") | ||
|
||
lb_languages! = wnd!.addListButton(201,5,6,160,250,"") | ||
lb_languages!.insertItemAt(0,"System Language") | ||
lb_languages!.insertItemAt(1,"German") | ||
lb_languages!.insertItemAt(2,"Dutch") | ||
lb_languages!.insertItemAt(3,"Saarlandish (Custom)") | ||
lb_languages!.selectIndex(0) | ||
lb_languages!.setCallback(BBjAPI.ON_LIST_SELECT,"updateLanguage") | ||
|
||
grid! = new BBjGridExWidget(wnd!,100,0,35,900,566) | ||
|
||
gosub fillGrid | ||
process_events | ||
|
||
fillGrid: | ||
sbc! = new SqlQueryBC(BBjAPI().getJDBCConnection("CDStore")) | ||
rs! = sbc!.retrieve("SELECT * FROM CDINVENTORY") | ||
|
||
REM add custom languge to the grid | ||
grid!.getLanguageManager().add("de_SL","BBjGridExWidget/Demo/assets/languages/de_SL.json") | ||
|
||
grid!.setData(rs!) | ||
return | ||
|
||
updateLanguage: | ||
declare auto BBjListSelectEvent ev! | ||
ev! = BBjAPI().getLastEvent() | ||
langauge$ = languages!.get(ev!.getSelectedIndex()) | ||
|
||
REM setting a new language requires a full rerender | ||
grid!.getLanguageManager().setLanguage(langauge$) | ||
grid!.setData(rs!) | ||
return | ||
|
||
resize: | ||
ev! = BBjAPI().getLastEvent() | ||
w=ev!.getWidth() | ||
h=ev!.getHeight() | ||
grid!.setSize(w,h) | ||
return | ||
|
||
byebye: | ||
bye |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"rem1":"Demo file as a sample for adding a custom translation", | ||
"rem2":"This language is inspired by the dialect spoken in Saarland", | ||
"rem3":"The Saarland is one of the Federal States of Germany, always worth a visit", | ||
"rem4":"https://goo.gl/maps/nCF7EYMPZvex2eJH6", | ||
"page": "Seit", | ||
"more": "Weida", | ||
"to": "Bis", | ||
"of": "An", | ||
"next": "Ennie voor", | ||
"last": "Letschdie", | ||
"first": "Eerschdie", | ||
"previous": "Serigg", | ||
"loadingOoo": "Waart emol...", | ||
"selectAll": "Alles auswähle", | ||
"searchOoo": "Finne...", | ||
"blanks": "Leerzeiche", | ||
"filterOoo": "Fildere...", | ||
"applyFilter": "Fildere...", | ||
"equals": "genauso wie", | ||
"notEquals": "annaschda als", | ||
"lessThan": "wenicher als", | ||
"greaterThan": "mehr als", | ||
"lessThanOrEqual": "weniger oder genauso vill wie", | ||
"greaterThanOrEqual": "genauso vill oder sogar mehr als wie", | ||
"inRange": "zwische", | ||
"contains": "mit", | ||
"notContains": "ohne", | ||
"startsWith": "fangt aan mit", | ||
"endsWith": "heerd uff mit", | ||
"andCondition": "UNN", | ||
"orCondition": "ODDER", | ||
"group": "Grupp", | ||
"columns": "Spalde", | ||
"filters": "Filter", | ||
"rowGroupColumns": "Pivot-Spalde", | ||
"rowGroupColumnsEmptyMessage": "Lass die Spalte hier falle wenn de se gruppiere maanschd.", | ||
"valueColumns": "Spalde mit Daate", | ||
"pivotMode": "Pivot-Instellung", | ||
"groups": "Gruppe", | ||
"values": "Weerte", | ||
"pivots": "Pivote", | ||
"valueColumnsEmptyMessage": "Lass die Spalte hier falle wenn de se sesammerechne willschd.", | ||
"pivotColumnsEmptyMessage": "Lass hier falle um e Pivot se knaupe", | ||
"toolPanelButton": "Werkzeich", | ||
"noRowsToShow": "Nix doo!", | ||
"pinColumn": "Spalte links feschdmache", | ||
"valueAggregation": "Gerechned", | ||
"autosizeThiscolumn": "Automadisch breeder mache", | ||
"autosizeAllColumns": "Mach all so breed wie's geht'", | ||
"groupBy": "Guppiere noo", | ||
"ungroupBy": "Nimmeh gruppiere noo", | ||
"resetColumns": "Mach widda so wie am Aanfang", | ||
"expandAll": "Alles zeie", | ||
"collapseAll": "Machh all zu", | ||
"toolPanel": "Werkzeich", | ||
"export": "Ausgenn", | ||
"csvExport": "Ausgenn als CSV", | ||
"excelExport": "Ausgenn fooa Excel (.xlsx)", | ||
"excelXmlExport": "Ausgenn aach foa Excel (.xml)", | ||
"pinLeft": "Feschdmache <<", | ||
"pinRight": "Feschdmache >>", | ||
"noPin": "Nidd feschdmache <>", | ||
"sum": "Alles zusamme", | ||
"min": "Kleenschdes", | ||
"max": "Greesches", | ||
"none": "Kenn", | ||
"count": "Wievill", | ||
"average": "So im Mittel", | ||
"filteredRows": "Versteggeld", | ||
"selectedRows": "Ausgewählt", | ||
"totalRows": "Am Enn insgesamd", | ||
"totalAndFilteredRows": "Alle Zeile zesamme", | ||
"copy": "Kopiere", | ||
"copyWithHeaders": "Kopiere mit Iwwerschrifte", | ||
"ctrlC": "Ctrl-C", | ||
"paste": "Dezumache", | ||
"ctrlV": "Ctrl-V" | ||
} |
Oops, something went wrong.