Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: How to put a function as a label for a button (for example) ?

  1. #11
    Sencha Premium User zmagyar's Avatar
    Join Date
    Mar 2012


    processConfig is available in Ext.js only. What would you suggest in ST for the same problem?

  2. #12
    Sencha Premium Member
    Join Date
    Mar 2013


    Hello zmagyar,

    Process Config, bad choice according to me
    Indeed, I've completely discarded Process Config as the choice to handle multilingual strings. Here are the reasons why:

    • First, this technic only works into ExtJS Framework, and not in Touch Framework, but the fact is I like genericity, => I prefer one single technic for both frameworks
    • Adding massive Process Config everywhere, in all components, pollute my Project Inspector in SA. It really should be avoided
    • Even with the use Process Config, it's not so easy to scan afterwards js files or SA json files, in order to scan all i18n function and fetch all texts to translate (see my previous posts to understand why), in order to keep synchronized some xml files that contains all translations (XLIFF file for example, in my case)
    Current logic used:
    For now, I'm using a simple technic that does the job and avoid all drawbacks exposed above
    (in my case). I've not yet enough feedbacks from this as I'm coding my very first app with Ext, so I hope all will be ok . Here the logic I use :
    • I code using SA, by putting default labels in english (native lang for the apps) like anyone would do. (no Process Config that would pollute my Project Inspector in SA)
    • When I code dynamically components, insert title etc... I always wrap my label/title/... with a custom i18n function like i18n('some text'). Anyone does this way already, nothing new
    • Then whenever I save my SA project and want to see the preview with strings translated, I launch then afterwards manually a php script that performs following operations (automatically):
      • it scans all js files in order to detect all blocks of code that contains an xtype and a label/string/etc (something that contains a string that should be translated) and hack it, for example:
        • Code:
          { xtype: 'passwordfield', label: 'Password' }
        • is remplaced by:
        • Code:
          { xtype: 'passwordfield', label: i18n('Password') }
      • After this code hacking, it scans again all js files in order to regex all i18n(.*), to know all strings that need to be translated. It updates therefore an XLIFF file for each locale my app supports:
        • The script adds a new record in the XLIFF for each locale whenever a new string is detected (by default the translation is the source string itself, therefore the app will work with no problem in any locale, even if human translation process hasn't yet been done)
        • The script marks as obsolete all records in the XLIFF for strings that no more exist in the app
      • I'm then happy with all my XLIFF files, generated automatically, I can then update them thanks to a soft that handles them (I use Qt Linguist)
    I've tried to code a js function (in order to avoid this js hacking), launched at the app initialization, in SA that sequentially finds all components in order to update title/label (insert i18n() wrapper). But it doesn't work at 100% as it relies on getter/setter in order to update string, but not all components has a getter/setter for their label.
    So i've find no solution except coding a post process on generated js files
    Further more, this post process is mandatory, whatever, in order to keep the XLIFF synchronized...

    Concerning this i18n() function, it fetchs the XLIFF content in order to know all strings translated into current locale used in the app (server pushes xliff translated into json for Extjs)
    this function yells if a string is not translated, and logs this warning on server side (Ext.Logger) for post analysis

    The drawback of this logic is the fact I need to launch a php script after SA saves the project (as it overrides all js previously generated), but no problem when I build, as Cmd is used as a post process, so it's easy to wrap it and trigger some process before really launching Cmd

    Nice to have in SA
    It would be nice if SA handles 2 more features (multilinguism would be so easy after that)

    Post process when saving project

    It would be nice to add a hook whenever SA saves project, in order to launch some external script.
    Indeed this logic is already used when building the app in SA, it launches an external script, which is Cmd

    So not a big deal, I guess, to add this feature when saving the project also (with the possibility to indicate a script different than the one used for building)

    In my case, i would use this feature to trigger a php script that scans js code, in order to generate XLIFF files

    Insert i18n function automatically
    Why not adding a param in SA that indicates some i18n function name that could be added for each label/text of each component ?

    For example, I would indicate in this param "i18n".
    After that, whenever SA generates js files, when it dumps strings that could be translated in another locale, it wraps it with the function name previously indicated

    • if no function has been indicated, then SA wraps with nothing, this is the current behavior
    • the developper is able to give the name he/she wants for the name of this i18n function. Some developper will use i18n(), other will use _(), etc...
    • it doesn't break at all current SA RAD
    • Easy to code, it's just some kind of plugin launched when generating js files. It relies on some internal ExtJS config that exposes all strings that can be translated, per component (roughly one per component)

    Hope this helps...

    Jerome Despatis

  3. #13
    Sencha Premium User zmagyar's Avatar
    Join Date
    Mar 2012


    Thanks for the extensive response. Meanwhile I have also checked the possibilities and I think we are going to go on a quite similar route to yours.

    As we are given up on Cmd quite a long time ago we already have a build script. Most likely I'm going to tweak this to process the generated js files just like you did.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts