B4J Question MenuBar - Multi Language

Discussion in 'B4J Questions' started by tdocs2, Sep 6, 2015.

  1. tdocs2

    tdocs2 Well-Known Member Licensed User

    Greetings.

    I should record a song - Stuck again....

    I use Derez Menu Designer to generate the JSON for the menus. Thank you, Derez:cool:

    I have generated two JSON strings - one in English and one in Spanish - there will be more, of course.

    The question is:

    How do I replace the JSON string for the menu depending on the PC language (System properties)?

    Attached is a simple project - menu is in English - JSON string in Spanish is shown as a comment above MenuBar_Action.

    Thank you for your replies.

    Sandy
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

    You cannot replace the JSON at runtime. However you can create two MenuBars and hide the one you don't want to show.
     
    tdocs2 likes this.
  3. tdocs2

    tdocs2 Well-Known Member Licensed User

    Thank you, Erel.
     
  4. Daestrum

    Daestrum Well-Known Member Licensed User

    Try this
    menudemo contains the xml for the menu and multi lang menu is the code.
    note this only allows for menu's 1 level deep, ie heading and items below
    file edit
    open ...
    save
    ...
    sort of menus
     

    Attached Files:

    tdocs2 likes this.
  5. tdocs2

    tdocs2 Well-Known Member Licensed User

    Thank you, Daestrum.

    Your knowledge of JAVA and XML is quite impressive.

    I received an error...

    Code:
    Program started.
    main._v6 (java line: 
    87)
    java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.lang.reflect.Method.invoke(Method.java:
    497)
        at anywheresoftware.b4j.object.JavaObject.RunMethod(
    JavaObject.java:130)
        at b4j.example.main._v6(main.java:
    87)
        at b4j.example.main._appstart(main.java:
    78)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
    62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
    43)
        at java.lang.reflect.Method.invoke(Method.java:
    497)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    93)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    84)
        at b4j.example.main.start(main.java:
    54)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$
    159(LauncherImpl.java:863)
        at com.sun.javafx.application.LauncherImpl$$Lambda$
    53/2041109752.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$
    172(PlatformImpl.java:326)
        at com.sun.javafx.application.PlatformImpl$$Lambda$
    46/1681433494.run(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$
    null$170(PlatformImpl.java:295)
        at com.sun.javafx.application.PlatformImpl$$Lambda$
    48/494743688.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$
    171(PlatformImpl.java:294)
        at com.sun.javafx.application.PlatformImpl$$Lambda$
    47/1685538367.run(Unknown Source)
        at com.sun.glass.ui.InvokeLaterDispatcher$
    Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$
    null$145(WinApplication.java:101)
        at com.sun.glass.ui.win.WinApplication$$Lambda$
    36/2058534881.run(Unknown Source)
        at java.lang.Thread.run(
    Thread.java:745)
    Caused by: java.io.FileNotFoundException: c:\temp\menudemo.xml (The system cannot find the 
    file specified)
        at java.io.FileInputStream.open0(Native Method)
        at java.io.FileInputStream.open(FileInputStream.java:
    195)
        at java.io.FileInputStream.<init>(FileInputStream.java:
    138)
        at java.io.FileInputStream.<init>(FileInputStream.java:
    93)
        at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:
    90)
        at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:
    188)
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:
    622)
        at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:
    189)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:
    812)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:
    777)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:
    141)
        at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:
    243)
        at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:
    348)
        at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:
    205)
        at b4j.example.main.decodeXML(main.java:
    168)
        ... 
    28 more
     
  6. Daestrum

    Daestrum Well-Known Member Licensed User

    Did you put the xml file in c;/temp directory as that is where it looks for it by default. As the error is 'file not found'

    if it is somewhere else just change this line in the code to point at it.
    Code:
    MenuBar1 = inline.RunMethod("decodeXML",Array("c:/temp/menudemo.xml",lang,MenuBar1))
     
    tdocs2 likes this.
  7. tdocs2

    tdocs2 Well-Known Member Licensed User

    Daestrum,

    As advertised.... Thank you.

    Sandy

    upload_2015-9-9_14-44-44.png
     
  8. Cableguy

    Cableguy Expert Licensed User

    That would mean creating 10+ menubar's if we had the need for 10+ languages support!

    At this moment, Apps created with B4J don't require an installer... I rekon that, if an installer of some sort were to be used, it would be possible, at install time, to assign a selected JSon string to the menu?
     
  9. tdocs2

    tdocs2 Well-Known Member Licensed User

    Paulo,

    You still have to develop a JSON string (I recommend Derez menu Designer) for each language.

    Where is the difficulty in creating multiple MenuBars and having a simple sub to make the one corresponding to the device language visible? This approach will also make it easier to test. The JSON strings would be stored in each MenuBar.

    There would be as much complexity in doing it at Install or Setup time...

    Best regards.

    Sandy

    PS: I never did Multilanguage in VB - so I would not know if there was a better paradigm.
     
  10. Cableguy

    Cableguy Expert Licensed User

    Hi Sandy,

    I could live with a bunch of JSon strings or JSon string files, if the mechanism to choose from them at appstart existed, The multiple menubars approach is overkill.
    In B4Ppc, that could also create native win32 apps based on the c# framework, we would use locale to select a translation file to use according to system prefs.
     
  11. Daestrum

    Daestrum Well-Known Member Licensed User

    I am currently writing a tool that takes a layout file and lets you create a language map for it. You can then include the language maps into the jar, and change at run time.
    It not only changes menus , but most controls Labels, buttons etc (it even change the empty message in a tableview along with the column headers).
    It's a tad rough at present to use, but anyone interested can have a copy to try and/or improve it.
    lang1.jpg lang2.png lang3.png lang4.png lang5.png
     
    Last edited: Sep 19, 2015
    Cableguy likes this.
  12. Cableguy

    Cableguy Expert Licensed User

    Seems you're on the right track! I will give it a go later in the day.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice