Repository: syncthing/syncthing
File: gui/default/syncthing/core/localeService.js (JavaScript)

Code before:
                        // sent by the browser will match "en" or "en-US", while "zh-TW" will
                        // match only "zh-TW" and not "zh" or "zh-CN".

                        var i,
                            browserLang,
                            matching,
                            locale = _defaultLocale;

                        for (i = 0; i < langs.length; i++) {
                            browserLang = langs[i];

                            if (browserLang.length < 2) {
                                continue;
                            }

                            matching = _availableLocales.filter(function (possibleLang) {
                                // The langs returned by the /rest/langs call will be in lower
                                // case. We compare to the lowercase version of the language
                                // code we have as well.
                                possibleLang = possibleLang.toLowerCase();
                                if (possibleLang.indexOf(browserLang) !== 0) {
                                    // Prefix does not match.
                                    return false;
                                }
                                if (possibleLang.length > browserLang.length) {
                                    // Must match up to the next hyphen separator.
                                    return possibleLang[browserLang.length] === '-';
                                }
                                // Same length, exact match.
                                return true;
                            });

                            if (matching.length >= 1) {
                                locale = matching[0];
                                break;
                            }
                        }
                        // Fallback if nothing matched
                        useLocale(locale);
                    });
                }
            }

            function useLocale(language, save2Storage) {
                if (language) {
                    $translate.use(language).then(function () {
                        document.documentElement.setAttribute("lang", language);
                        if (save2Storage && _localStorage)
                            _localStorage[_SYNLANG] = language;
                    });
                }

Review comment (suggestion):
```suggestion
                                    // Must match up to the next hyphen separator
```

Code after:
                        // sent by the browser will match "en" or "en-US", while "zh-TW" will
                        // match only "zh-TW" and not "zh" or "zh-CN".

                        var i,
                            browserLang,
                            matching,
                            locale = _defaultLocale; // Fallback if nothing matched

                        for (i = 0; i < langs.length; i++) {
                            browserLang = langs[i];

                            if (browserLang.length < 2) {
                                continue;
                            }

                            matching = _availableLocales.filter(function (possibleLang) {
                                // The langs returned by the /svc/langs call will be in lower
                                // case. We compare to the lowercase version of the language
                                // code we have as well.
                                possibleLang = possibleLang.toLowerCase();
                                if (possibleLang.indexOf(browserLang) !== 0) {
                                    // Prefix does not match
                                    return false;
                                }
                                if (possibleLang.length > browserLang.length) {
                                    // Must match up to the next hyphen separator
                                    return possibleLang[browserLang.length] === '-';
                                }
                                // Same length, exact match
                                return true;
                            });

                            if (matching.length >= 1) {
                                locale = matching[0];
                                break;
                            }
                        }
                        useLocale(locale);
                    });
                }
            }

            function useLocale(language, save2Storage) {
                if (language) {
                    $translate.use(language).then(function () {
                        document.documentElement.setAttribute("lang", language);
                        if (save2Storage && _localStorage)
                            _localStorage[_SYNLANG] = language;
                    });
                }
            }