4
11 Comments

Help needed - easiest way to translate an SPA into multiple languages?

http://beta.goshare.at/

We've just launched goshare (beta.goshare.at/) and had a lot of interest from beta testers outside of the UK asking if pages could be built in different languages.

The beta testers have kindly offered to help with the translations, but as this was not on our short-term roadmap I'm concerned about implementing it if it takes too long.

Are there any tools out there which make this easy for SPAs?

submitted this linkon August 29, 2019
  1. 2

    Hey @jonnymatthews. What is your tech stack for the SPA? We are currently evaluating i18next at $dayjob - it seems to be the industry standard for internationalizing a JavaScript codebase. Since our SPA is a React app we are specifically evaluating react-i18next, which is a thin wrapper around i18next adding some React-specific integration points.

    The way this (and almost all i18n libraries) work is that you replace all the English text in your codebase with a keyword instead, so e.g. let msg = "Hello, world" becomes let msg = t("HELLO_WORLD"). You also need to provide a translations file (this is where you beta tester volunteers come in!) which looks something like:

    {
      "en": {
        "HELLO_WORLD": "Hello, world!"
      },
      "es": {
        "HELLO_WORLD": "¡Hola, mundo!"
      }
    }
    

    It's a going to be a lot work no matter what specific service you choose - AFAIK there's no plug-and-play solution since your engineers are going to need to replace all the English messages in your codebase no matter what.

    Hope this helped, happy to chat further about this if you want.

    1. 1

      Thanks a lot, i18next looks like it would make the whole process a lot easier (passed it onto our dev to take a look). We really dont have much text on the main pages, but your comment just made me think of pages like our privacy policy which won't be fun to translate into 5 different languages!

  2. 2

    Are you using any kind of framework? As many have translation support built in. I've used https://lokalise.co/ in the past, though their might be better ones, it's been a while. But basically how it tends to work is you have a reference identifier that is replaced from an array in the specific language. I.e. you might have something like __('intro_text') then an en.json and a de.json (or any format really) each of which will have the line of text that corresponds to the 'intro_text' key, the __() function in this example just replaces intro_text with whatever language the user has selected, you would also fallback to english if the key was missing. The above site allows you to create the keys and people can provide translations for it, then you can export in multiple formats. I used it with laravel and used a console command to automatically grab the latest versions using their API.

    1. 2

      Thats super helpful thanks. We are using vue.js? I had a look at lokalise.co and couldn't see anywhere on their website or documentation about SPA support - have you tried it?

      1. 2

        I bumped into the same problem recently for my project. I looked into lokalise.co but it's seems a bit bloated and the pricing structure may not be suitable for small projects.
        I ended up hacking a custom solution. You can see a screenshot here: https://imgur.com/a/ywuLPPX

        It's basically a google spreadsheet-like system focused on editing the translation of keys and exporting scopes and sub-scopes in different languages.
        There a simple api to access scopes and sub-scopes as JSON files, and to export the entire files structure for CDN hosting.
        And yes, it does integrate a magical [ask AI] button to get the translation from deepl.com ;-)
        I've built a Vue plugin for it.

        It's a multi-tenant, multi-project platform, and I'm currently testing it on a few projects https://imgur.com/a/VELJZuT
        I was thinking of opening it to other people and share the cost on a usage basis (building more of a community, less of a SaaS business).
        I'd be happy to open it to your dev team, if you'd like!

        1. 1

          That sounds amazing, I'm meeting up with the developer tomorrow so I'll run through this. Whats the best way to get in touch? My email is jonny @ goshare.at

      2. 2

        I personally use Quasar which you can use to create vue.js SPA, PWA, electron and mobile (cordova) apps, that has i18n support built in https://quasar.dev/options/app-internationalization, I haven't used it yet but it seems to suggest using http://kazupon.github.io/vue-i18n/ so you can do it without quasar and pure vue.js (though quasar is extremely useful), it's been a while since I've used lokalise.co but I'm 99.9% sure it will have an output format that you will be able to use with that. Hope this helps.

        1. 2

          Also SPA support won't be a thing on it's own because it doesn't matter if something is an SPA or PWA or whatever, it's the underlying technology that is important. In this case you are using vue.js. Anyway, I found this for you which from a quick look looks like it's exactly what you are after - https://blog.lokalise.co/vue/

          1. 1

            Thanks a lot @Kode. I'm not actually the developer so going to run this through with him tomorrow to see what he says! Appreciate the help. Just noticed you are based in the UK, if there's anything I can do to help with design/marketing give me a shout :)

            1. 1

              Wow... are you saying my design skills are that bad? ;)
              Thanks though, I'm always open to constructive criticsm.
              The last link I sent you should be all your developer needs, it's not specific to lokalise at all so you could swap that part out with whatever you want, but it appears to have all the bits you will need to add translation support. Basically all you will need is a dropdown somewhere with the available languages which when clicked will replace the text with the translation.

              1. 1

                hahaha not at all! Sounds good, fingers crossed we can get everything set up quickly