wikimedia / jquery.i18n

🌐 jQuery based internationalization library
GNU General Public License v2.0
702 stars 143 forks source link

JSON Object in Object #122

Open fellipejsousa opened 7 years ago

fellipejsousa commented 7 years ago

Friends library has support for objects inside objects because my script is criticizing: Uncaught TypeError: message.indexOf is not a function


example json:

{
    "en": {
        "appname-title": "Example Application",
        "appname-sub-title": "An example application with jquery.i18n",
        "appname-header-introduction": "Introduction",
         "example": {
                "appname-title": "Example Application",
               "appname-sub-title": "An example application with jquery.i18n"
        },
        "appname-about": "About this application",
        "appname-footer": "Footer text"
        },
    "ml": {
        "appname-title": "അപ്ലിക്കേഷന്‍ ഉദാഹരണം",
        "appname-sub-title": "jquery.i18n ഉപയോഗിച്ചുള്ള അപ്ലിക്കേഷന്‍ ഉദാഹരണം",
        "appname-header-introduction": "ആമുഖം",
         "example": {
                "appname-title": "Example Application",
               "appname-sub-title": "An example application with jquery.i18n"
        },
        "appname-about": "ഈ അപ്ലിക്കേഷനെപ്പറ്റി",
        "appname-footer": "അടിക്കുറിപ്പു്"
    }
}
}
ghost commented 6 years ago

Same issue !

SossenSystems commented 4 years ago

Me to... How can i call an object in object, like content.title

Hrithik248 commented 1 year ago

The error message "Uncaught TypeError: message.indexOf is not a function" is thrown when you try to use the indexOf() method on a variable that is not a string. It seems like you are trying to use this method on an object. The Friends library does support objects inside objects. You can access the nested object by using dot notation or bracket notation. Here's an example of how you can access the nested object:

var json = {
    "en": {
        "appname-title": "Example Application",
        "appname-sub-title": "An example application with jquery.i18n",
        "appname-header-introduction": "Introduction",
         "example": {
                "appname-title": "Example Application",
               "appname-sub-title": "An example application with jquery.i18n"
        },
        "appname-about": "About this application",
        "appname-footer": "Footer text"
        },
    "ml": {
        "appname-title": "അപ്ലിക്കേഷന്‍ ഉദാഹരണം",
        "appname-sub-title": "jquery.i18n ഉപയോഗിച്ചുള്ള അപ്ലിക്കേഷന്‍ ഉദാഹരണം",
        "appname-header-introduction": "ആമുഖം",
         "example": {
                "appname-title": "Example Application",
               "appname-sub-title": "An example application with jquery.i18n"
        },
        "appname-about": "ഈ അപ്ലിക്കേഷനെപ്പറ്റി",
        "appname-footer": "അടിക്കുറിപ്പു്"
    }
};

console.log(json.en.example["appname-title"]); // Output: Example Application
console.log(json.ml["appname-footer"]); // Output: അടിക്കുറിപ്പു്