Question T5054
Visible to All Users

Can translations live and be accessed from centralized json files

created 5 years ago (modified 5 years ago)

Angular 9+

It looks like you can specify the translated strings inside of the survey definition like this. In our case we sometimes need to massage our text a bit using javascript/typescript functions ex) format strings, building strings, translating text in "type": "html" elements, etc…

One way we were thinking about was either making a custom locale file with our strings and accessing them, or appending to existing language files.
Accessing it like: Survey.surveyLocalization.locales[locale][locStringId]

  1. Any suggestions on this; as it feels weird and not the correct way to go
  2. Is there a way to reference translation variables in the survey definition instead of specifying every language ex)
Code
text: { default: "5 (the best)", de: "5 (Das beste)", fr: "...", ... } },

Answers approved by surveyjs Support

created 5 years ago

Hello,

Survey JSON contains localized strings of the "end-user" localizations: e.g. it allows to set different question title texts for different languages. All technical strings (like "Next page" button titles) are stored in Survey.surveyLocalization.locales[locale]

Thus where to store localized text is depends on what text to you want to localize.

Thanks, Serge
SurveyJS Team

    Other Answers

    created 5 years ago (modified 5 years ago)

    We have a few technical string changes as well so were planning on updating those as mentioned above.

    I guess my question is being able to centralize the end-user localizations to send to translators to update; without having to manually move the strings over; or sending them a SurveyJSON to parse through.

    file sent to translators xliff, or just raw json
    fr.json

    Code
    { key: <translated value>, key: <translated value> ... }

    and being able to read this value into the Survey without having to manually; or without having to write script that takes translations putting it into the write question in the Survey JSON

    Code
    { "type": "text", "name": "firstName", "title": {firstNameQuestionTitle}, "isRequired": true, }

    Where the correct locale file for these strings is picked to grab the variable from

    Wondering if you have any ideas.

      Comments (1)

        Hello,
        We have code and UI in our SurveyJS Creator library. If you use Creator, then you can just use creator.translation property that reference the Translation object. This object does what you need. Unfortunately it doesn't come with the library, since you do not need it when end-user runs survey. Here is its code.
        You can check how it works by playing with Survey Creator Translation tab.

        Thank you,
        Andrew
        SurveyJS Team