Open TeemuSuoranta opened 8 years ago
Excellent write-up! Thanks @TeemuSuoranta, Let's build on this soon.
My main concern is to have some default language from wordpress but also to have language switcher with javascript so that the enduser always has clear guidance what to do in the event of database error.
The error message could be displayed for the user's language. There's a couple of ways:
1) Try to guess the language from browser (bad) 2) Try to guess the language from url (better) 3) Try to guess the language from url with a default language (best)
What do we know from the url that was used?
a) https://wordpress.test (could be anything, no luck here) b) https://fi.wordpress.test (this is Finnish) c) https://wordpress.test/en/contact (this is English) d) https://wordpress.fi (could be Finnish, wouldn't bet on it, though)
There's a two-letter abbreviations for languages that can help us and they are standardized (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).
What we could do: 1) Save the list of language codes as an array 2) Regex the url for the subdomain and "first part" (/fi/) 3) If there's match, use a language file that is named just like the language code. You can do this in a PHP or JS file (like /languages/fi.php). Include language and populate content. If the translation doesn't exist, use fallback language. 4) No match? Use default language.
Problems: