Translation / internationalization from script code

  • Christian
        vor 5 Jahren #14935

        Use case: I would like to support multiple languages in my client app. According to https://community.simplifier.io/doc/current-release/#8226 , this is supported for translatable strings from widgets, where both the extraction of the strings to the po file as well as the run-time actual translation lookup is done.

        However, there are also translatable (user-visible) strings in the script code (client-side scripts), i.e. things like mymessage=”This is an important message”. How is this supported by the po files? To be more concrete, we would like to know:

        • 1. How do we get the translatable strings from script code extracted into the po files at development time? Either with some abstract message key as msgid in the po file, or with the original language’s string as msgid?
        • 2. How do we do the translation lookup at runtime from within our script code? I expect something like mymessage=gettext(“This is an important message”) or similar.

        The academy article https://community.simplifier.io/doc/current-release/#8226 does not say anything about this. Maybe some sentences about this translation step should be added there. Thanks!

        Mathieu Roll
            Has successfully completed the online course Introduction
            Has successfully completed the online course Intermediate (200)
            Has successfully completed the online course Advanced (300)
            Has successfully completed the online course Basics (100)
          vor 5 Jahren #15226
          Up
          1
          Down
          ::

          Hi,

          first of all you need a dummy screen where you can place translatable widgets to use.

          Then you have different ways to use them.

          I’ve created a demo application for you with 4 ways to get the translations.

          Please find attached the transport of the demo application.

          To test your application in other languages you can add this query parameter to your application url.

          ?sap-ui-language=en

          https://files.simplifier.io/f/42d6b3cb8ffc4d089fd0/?dl=1

          Christian
              vor 5 Jahren #15346
              Up
              0
              Down
              ::

              Ok, the “dummy screen” method is usable (although not at all elegant) and you could probably add it to the mentioned documentation page.

              However, we encountered one more issue with translations: Is there are a suggested way of defining translatable strings with placeholder or format arguments, i.e. the printf() equivalent in Javascript? Example: popup(“Should the file %s be deleted”, filename)? String concatenation would work for one single language, but is not at all translatable, where instead strings with placeholder arguments are needed.

              Google brings up suggestions like these https://stackoverflow.com/a/4673436 which is a small added String.format() function. But this requirement is needed so often that we would expect a common solution either in OpenUI5 or in Simplifier. Any ideas?

              Mathieu Roll
                  Has successfully completed the online course Introduction
                  Has successfully completed the online course Intermediate (200)
                  Has successfully completed the online course Advanced (300)
                  Has successfully completed the online course Basics (100)
                vor 5 Jahren #15366
                Up
                0
                Down
                ::

                Hi,

                the simplifier does support bindings and expression bindings like explained here.

                https://openui5.hana.ondemand.com/1.52.29/#/topic/daf6852a04b44d118963968a1239d2c0

                The same way i have used in the demo application.

                So you can use a text field where you can make a expression binding with concat.

                {= ${i18n>/Translations$test1$text} + ${variableHolder>/myVar} + ${i18n>/Translations$test2$text} }

                So if you have a text field with the expression binding you will get the following result

                2019-05-10-16-00-55-App-Example-Translation 2019-05-10-16-01-02-App-Example-Translation 2019-05-10-16-01-10-App-Example-Translation 2019-05-10-16-02-50-Example-Translation 2019-05-10-16-03-08-App-Example-Translation

                Christian
                    vor 5 Jahren #15370
                    Up
                    0
                    Down
                    ::

                    Thanks for replying, but: My statement is that a concat of mutiple separately translated strings is unusable for more complex translations. Instead, the translation system must be able to provide msgstr/msgid in the po files that contain placeholder or similar, because only this way a separate translator person has any chance to give a meaningful translation. Example: “Should the file {0} be deleted?” – the word ordering in the sentence might be changed completely for other languages. Hence, any professional language translation system in software usually supports those placeholders as part of the translatable strings.

                    Having said that, in https://openui5.hana.ondemand.com/1.52.29/#/topic/df86bfbeab0645e5b764ffa488ed57dc it seems the {0}, {1}, … syntax is already supported in OpenUI5, where the translatable string “Hello {0}” is transformed into “Hello World” in the client script code?

                    Christian
                        vor 5 Jahren #16318
                        Up
                        0
                        Down
                        ::

                        And yet another question: When writing translatable strings in script code, the translation systems usually have two more features on top of just plain fixed strings. One, replacements are possible (as discussed above, Example: “Should the element {0} be deleted?”)

                        The second important feature for high-quality translations from script code is support for plural forms. Example: “Should 1 element be deleted” vs. “Should 2 elements be deleted”, where the number argument must be used for choosing among several possible plural forms. Between English and German this seems to be easy, because by coincidence both languages have exactly two forms (singular/plural) with the same rules. Other languages may have completely different rules and forms (e.g. Arabic has six plural forms). Hence, the translation system must enable some way of specifying this situation. See e.g. here for how Angular solves this topic: https://angular.io/guide/i18n#translating-plural-and-select-expressions which isn’t particularly elegant either but at least some usable solution.

                        What do you suggest here? Also, I would kindly ask you to extend your “Language” chapter in the documentation to describe the translations from script code, because right now it is still not mentioned there how to do this. Once you’re at it, please remember to also mention the two features discussed here (replacements and plural forms). Thanks!

                      Ansicht von 6 Beiträgen – 1 bis 6 (von insgesamt 6)

                      You must be logged in to reply to this topic.