JS文件开头存放"resources"(UI个组件的文本)的位置和方法

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

人们在为标签和类似的东西输入文本时做了什么?

我将它们输入到项目中,但这非常混乱,因为我不得不搜索所有代码才能找到和编辑文本。即

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

我考虑过将它们放在“配置”部分,但随后我需要执行 getNameOfConfig,即

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

是否有不同的方法?我真的不想重新发明轮子

我也想过直接在组件上放置一个对象即

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

我相信这样我就可以做 this.uiRes.saveButtonText 而不是使用 getter。

我认为我当然需要改进它,因为当我需要编辑 UI 元素的文本时,我正在查找我的代码,这样做会更容易,对吗?

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

是否有一些内置的方法可以做到这一点?

None 您提出的解决方案将有效,除非您在 initComponent() 函数中定义所有组件配置(看看 this fiddle - 它只是不呈现)。使用 'this' 只是有问题。

您要找的实际上是本地化支持。官方指南(支持)是将所有字符串放在组件配置中(在 config: {} 块中不是必需的)并使用覆盖进行翻译。但这个解决方案远非理想。

如果您真的在寻找本地化解决方案,我强烈建议您阅读@Saki 的Localization of Ext Applications article。这是对什么是 available\advantages 等的很好的分析 + 提出的解决方案。这比我在这里写的任何东西都要好..

如果本地化不是您的目标,我会按原样保留代码中的文本。