Skip to content

Commit

Permalink
feat: allow changing the grid language (#128)
Browse files Browse the repository at this point in the history
See #122 , #128

Resolves #122
  • Loading branch information
hyyan committed May 1, 2019
1 parent 4e3c546 commit 8fe01f0
Show file tree
Hide file tree
Showing 16 changed files with 62,525 additions and 44,639 deletions.
45 changes: 17 additions & 28 deletions BBjGridExWidget.bbj
Expand Up @@ -33,6 +33,7 @@ use ::BBjGridExWidget/BBjGridExWidgetToolpanel.bbj::BBjGridExWidgetToolpanel
use ::BBjGridExWidget/BBjGridWidgetCellEditingEvent.bbj::BBjGridWidgetCellEditingEvent
use ::BBjGridExWidget/BBjGridWidgetContextMenuEvent.bbj::BBjGridWidgetContextMenuEvent
use ::BBjGridExWidget/BBjGridWidgetRowEditingEvent.bbj::BBjGridWidgetRowEditingEvent
use ::BBjGridExWidget/BBjGridExWidgetLanguageManager.bbj::BBjGridExWidgetLanguageManager


rem /**
Expand Down Expand Up @@ -332,6 +333,7 @@ class public BBjGridExWidget extends BBjWidget
rem * @Enterprise
rem */
field protected BBjGridExWidgetSidebar Sidebar! = new BBjGridExWidgetDefaultSidebar(#this!)
field protected BBjGridExWidgetLanguageManager LanguageManager! = new BBjGridExWidgetLanguageManager()
rem /**
rem * The grid statusbar
rem *
Expand Down Expand Up @@ -408,7 +410,7 @@ class public BBjGridExWidget extends BBjWidget
#setLicenseKey(str(lic!))
FI

html$="<html><head><style>html,body{margin:0;padding:0,height: 100%} .ag-root.ag-layout-normal{height: inherit !important;}</style></head><body><div id='event-bridge-"+ str(#GRIDID$) +"' onClick='window.basisDispatchCustomEvent(this, event.payload)'></div><div id='" + str(#GRIDID$) + "' style=""height: 100%"" class=""ag-theme-balham""></div></body></html>"
html$="<html><head><meta charset='UTF-8'><style>html,body{margin:0;padding:0,height: 100%}</style></head><body><div id='event-bridge-"+ str(#GRIDID$) +"' onClick='window.basisDispatchCustomEvent(this, event.payload)'></div><div id='" + str(#GRIDID$) + "' style=""height: 100%"" class=""ag-theme-balham""></div></body></html>"

if (info(3,6)<>"5" and #Debug>0) then
call "BBjGridExWidget/util/EnableDebugger.bbj"
Expand Down Expand Up @@ -473,8 +475,8 @@ class public BBjGridExWidget extends BBjWidget
close (ch)
#injectScript(script$)
rem include locale files
locale! = stbl("!LOCALE")
locale$ = str(locale!.replaceAll("_","-"))
locale! = #getLanguageManager().getLanguage()
locale$ = str(locale!.replaceAll("_","-").replaceAll("_","-"))
dateJsLocalePath$ = distBase$ + "/../vendor/Datejs/build/date-" + locale$ + ".js"
isLocale = 0
ch=unt
Expand Down Expand Up @@ -933,6 +935,14 @@ class public BBjGridExWidget extends BBjWidget
methodret #Sidebar!
methodend
rem /**
rem * Get the language manager instance
rem *
rem * @returns BBjGridExWidgetLanguageManager
rem */
method public BBjGridExWidgetLanguageManager getLanguageManager()
methodret #LanguageManager!
methodend
rem /**
rem * Get the grid statusbar instance
rem *
rem * @return BBjGridExWidgetStatusBar
Expand Down Expand Up @@ -1812,7 +1822,6 @@ class public BBjGridExWidget extends BBjWidget

method private void performGridDataUpdate()


if (! #IsReady!)
methodret
FI
Expand All @@ -1838,7 +1847,7 @@ class public BBjGridExWidget extends BBjWidget
comma$=a$(5,1)
dot$=a$(6,1)
fi

options! = new JsonObject()
options!.addProperty("animateRows",Boolean.valueOf(1))
options!.addProperty("allowContextMenuWithControlKey",Boolean.valueOf(0))
Expand All @@ -1860,6 +1869,7 @@ class public BBjGridExWidget extends BBjWidget
options!.addProperty("rowHeight",#RowHeight!.longValue())
options!.addProperty("sideBar",#Sidebar!.toString())
options!.addProperty("statusBar",#Statusbar!.toString())
options!.addProperty("localeText" , #getLanguageManager().getLanguageKeys())
autoGroupColumnDef! = new JsonObject()

if #GroupMultiAutoColumn! = 0 then
Expand All @@ -1882,11 +1892,10 @@ class public BBjGridExWidget extends BBjWidget
context!.addProperty("columnsGroup", new Gson().toJson(#ColumnGroups!))
context!.addProperty("numberGroupSep",comma$)
context!.addProperty("numberDecimalSep",dot$)
context!.addProperty("locale",stbl("!LOCALE"))
context!.addProperty("locale",#getLanguageManager().getLanguage())
context!.addProperty("contextMenu",#ContextMenu!.toString())
context!.addProperty("NUMBERS_RENDERER_GROUP_SEPARATOR",comma$)
context!.addProperty("NUMBERS_RENDERER_DECIMAL_SEPARATOR",dot$)
context!.addProperty("locale",stbl("!LOCALE"))
context!.addProperty("contextMenu",#ContextMenu!.toString())

if (#SelectionMode! = BBjGrid.GRID_SELECT_ROW) and #MultipleSelection! = 0 then
Expand Down Expand Up @@ -2130,24 +2139,4 @@ class public BBjGridExWidget extends BBjWidget
methodret "data:image/png;base64, "+b64$
methodend

classend




















classend
100 changes: 100 additions & 0 deletions BBjGridExWidgetLanguageManager.bbj
@@ -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
76 changes: 76 additions & 0 deletions Demo/LanguageDemo.bbj
@@ -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
79 changes: 79 additions & 0 deletions Demo/assets/languages/de_SL.json
@@ -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&auml;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&auml;hlt",
"totalRows": "Am Enn insgesamd",
"totalAndFilteredRows": "Alle Zeile zesamme",
"copy": "Kopiere",
"copyWithHeaders": "Kopiere mit Iwwerschrifte",
"ctrlC": "Ctrl-C",
"paste": "Dezumache",
"ctrlV": "Ctrl-V"
}

0 comments on commit 8fe01f0

Please sign in to comment.