Search code examples
extjsextjs4extjs4.1extjs4.2extjs5

Place and ways for storing "resources" (texts for UI components) at beginning of JS file


What are people doing for entering texts for labels and thing like that ?

I had them entered into the items but this was pretty messy as I had to search through all my code just to find and edit texts. i.e.

     {
        xtype: 'fieldcontainer',
        fieldLabel: 'Save', // Abstracting this to a common place ???

I thought about putting these in the "config" section but then I need to do a getNameOfConfig i.e.

 config: {
    cancelButtonText: 'Cancel',
    saveButtonText: 'Save',
    deleteButtonText: 'Delete',
    ........

Is there a different approach? I really don't want to re-invent the wheel.

I also thought of just placing an object directly on the component i.e.

 uiRes: {
    cancelButtonText: 'Cancel',
    saveButtonText: 'Save',
    deleteButtonText: 'Delete',
    ........

I believe this way I can just do a this.uiRes.saveButtonText rather than using a getter.

I think I certainly need to improve it as when I need to edit text for a UI element I am looking up and down my code and do this would be easier right?

 {
    xtype: 'fieldcontainer',
    fieldLabel: this.uiRes.saveButtonText //OR// getSaveButtonText()

Is there some built in way of doing this ?


Solution

  • None of your proposed solutions will work unless you define all your components configs inside initComponent() functions (take a look at this fiddle - it just don't render). Using of 'this' is just problematic.

    What are you looking for is in fact localization support. Official guidelines (support) is to put all string in component config (not necessary in config: {} block) and use overrides for translations. But this solution is far from ideal.

    If you are really looking for localization solution, I would highly recommend to read Localization of Ext Applications article by @Saki. It's great analysis of what's available\advantages etc. + proposed solution. It is way better than anything i would wrote here..

    If localization is not your target I would just leave the texts in code as is.