GetTranslationFunc will return back a function that can be used to translate strings into the currently set locale.
(reader LocaleReader)
| 46 | // GetTranslationFunc will return back a function that can be used to translate |
| 47 | // strings into the currently set locale. |
| 48 | func GetTranslationFunc(reader LocaleReader) (TranslateFunc, error) { |
| 49 | locale, err := determineLocale(reader) |
| 50 | if err != nil { |
| 51 | locale = defaultLocale |
| 52 | } |
| 53 | |
| 54 | rawTranslation, err := loadAssetFromResources(locale) |
| 55 | if err != nil { |
| 56 | rawTranslation, err = loadAssetFromResources(defaultLocale) |
| 57 | if err != nil { |
| 58 | return nil, err |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return generateTranslationFunc(rawTranslation) |
| 63 | } |
| 64 | |
| 65 | // ParseLocale will return a locale formatted as "<language code>-<region |
| 66 | // code>" for all non-Chinese languages. For Chinese, it will return |
no test coverage detected