Live data from Hacker News

Lessons From Linguistics: i18n Best Practices for Front-End Developers

shopify.engineering

11–20 of 102 posts

Re: Lessons From Linguistics: i18n Best Practices for Front-End Developers

#11
post #8

The post is interesting as it exposes the problem statement. Unfortunately, I expected from a Shopify Engineering blog that it would provide solutions to this problem like a JS library for i18n. Disclaimer: As I'm not a frontend developer I'm not familiar with the ecosystem solutions.

The article shows solutions and they're library agnostic, you can use the approaches shown in pretty much any modern intl library.

Re: Lessons From Linguistics: i18n Best Practices for Front-End Developers

#13

This is a good article, though as someone who prefers references/tables to prose for technical topics, the real find for me was the link out to the Unicode CLDR project (which sadly contains a LOT of broken links right now due to a data migration effort but I'll bookmark it & hopefully it'll be navigable in future). As someone with a Polish partner, who also fluently speaks my own weird minority local language (Irish…

The CLDR plural rules for Irish are here https://www.unicode.org/cldr/charts/42/supplemental/language... Not quite as complex as the ones for Breton https://www.unicode.org/cldr/charts/42/supplemental/language... but of course they might be wrong.

Re: Lessons From Linguistics: i18n Best Practices for Front-End Developers

#14
I've found that I need to support localization from the very start.

I never display a quoted string. I always use Apple's tokenization (or create my own, if doing server code).

Apple has terrific support for localization, which puts the onus on us, to honor it. I have some basic extensions that I use to support localization in my coding[0-2], but there's also just stuff I need to keep in mind, all the time.

There has been discussion of how to deal with things like word order in different languages. For example, in Germanic languages, the modifier usually precedes the subject, while in Romance languages, it tends to be the opposite.

Thankfully, Apple supports the "$" format for sprintf strings[3], so we can do stuff like this:

    import Foundation

    let localizationAssets = [
        (format: "The %1$@ %2$@", modifier: "white", subject: "horse"),
        (format: "Le %2$@ %1$@", modifier: "blanc", subject: "cheval")
    ]

    func localizedHorse(_ inLocalization: Int) -> String {
        String(
            format: localizationAssets[inLocalization].format,
            localizationAssets[inLocalization].modifier,
            localizationAssets[inLocalization].subject
        )
    }

    // English (Prints "The white horse")
    print(localizedHorse(0))
    // French (Prints "Le cheval blanc")
    print(localizedHorse(1))

[0] https://github.com/RiftValleySoftware/RVS_Generic_Swift_Tool...

[1] https://github.com/RiftValleySoftware/RVS_Generic_Swift_Tool...

[2] https://github.com/RiftValleySoftware/RVS_Generic_Swift_Tool...

[3] https://developer.apple.com/library/archive/documentation/Co...

Re: Lessons From Linguistics: i18n Best Practices for Front-End Developers

#15
post #7

Is there some kind of Auto-i18n where the function sends a request to a server if there is no localization available? The server could in turn request a translation from a service and add it to the localization files

This does exist, there are a few translation-as-a-service companies that offer more or less what you want. It's not exactly as you are describing, but I have a pipeline setup for an app I built that will extract and machine translate strings at build time. It would be pretty trivial to just do the extraction part and send off the files to whatever endpoint you want (being a human or a machine translating in the end), if you wanted to "roll your own".

Re: Lessons From Linguistics: i18n Best Practices for Front-End Developers

#16
post #7

Is there some kind of Auto-i18n where the function sends a request to a server if there is no localization available? The server could in turn request a translation from a service and add it to the localization files

I believe the library mentioned in the article (i18next) provides the necessary hooks to do this. See ‘saveMissing’ option [1].

Though you need a backend to save this and manage translations. The maintainer of that library, locize, business model is to provide such a service.

[1] https://www.i18next.com/how-to/extracting-translations

Re: Lessons From Linguistics: i18n Best Practices for Front-End Developers

#17

Don't forget Right-To-Left languages, that also affects how UI elements are arranged (position within the page) and rendered (input widgets like sliders get reversed).

I think the currently blessed CSS solution is to only use {inline,block}-{start,end} https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_logical... in place of {left,right,top,bottom} which then automagically supports even vertical scripts like Traditional Mongolian, but most people probably don't think that far ahead when just starting out.

Re: Lessons From Linguistics: i18n Best Practices for Front-End Developers

#18

I've found that I need to support localization from the very start. I never display a quoted string. I always use Apple's tokenization (or create my own, if doing server code). Apple has terrific support for localization, which puts the onus on us, to honor it. I have some basic extensions that I use to support localization in my coding[0-2], but there's also just stuff I need to keep in mind, all the time. There has…

The code example should rather be an example of what not to do. This method of concatenating different parts of sentences would fall short for any language where the adjective and noun change the form depending on each other and the context (ex. cases). Most Slavic languages make heavy use of this concept. The solution is to just have the full sentence as a single string and let the translation team write it out in its entirety. Avoid interpolating nouns, adjectives, verbs etc. as much as possible.

Re: Lessons From Linguistics: i18n Best Practices for Front-End Developers

#19
> The order of the words is hardcoded, with “added” preceding the date. This would be incorrect in many languages, from Dutch (“1 januari toegevoegd”)

This is simply not true. Since English and Dutch are both Germanic languages they largely work the same way. Saying "Toegevoegd: 1 januari" would be just fine. By using "1 januari toevoegd" you're syntactically changing the sentence.

Re: Lessons From Linguistics: i18n Best Practices for Front-End Developers

#20

I've found that I need to support localization from the very start. I never display a quoted string. I always use Apple's tokenization (or create my own, if doing server code). Apple has terrific support for localization, which puts the onus on us, to honor it. I have some basic extensions that I use to support localization in my coding[0-2], but there's also just stuff I need to keep in mind, all the time. There has…

The code example should rather be an example of what not to do. This method of concatenating different parts of sentences would fall short for any language where the adjective and noun change the form depending on each other and the context (ex. cases). Most Slavic languages make heavy use of this concept. The solution is to just have the full sentence as a single string and let the translation team write it out in i…

It was just a silly example.

Of course, you are correct, but we don't always have the luxury of being able to hand an entire string to a localization team, and some programmatic interpretation often needs to be done.

The best way to deal with it, is to design code that allows entire sentences to be handed to translators (I do that, most of the time).

The other advantage of writing localized content, is that it can be easily modified by non-engineers, like marketing folks. Talking points and corporate glossaries are important. Even if we don't plan to localize, it doesn't hurt to use localization tokenized content.

Post reply on HN