diff --git a/assets/src/i18n/index.js b/assets/src/i18n/index.js index 1afe0925..013c8d31 100644 --- a/assets/src/i18n/index.js +++ b/assets/src/i18n/index.js @@ -9,8 +9,35 @@ import zhTW from './zh-tw.yaml' Vue.use(VueI18n) +let locale = (navigator.language || navigator.browserLangugae).toLowerCase() +switch (true) { + case /^en.*/i.test(locale): + locale = 'en' + break + case /^fr.*/i.test(locale): + locale = 'fr' + break + case /^pt.*/i.test(locale): + locale = 'pr' + break + case /^ja.*/i.test(locale): + locale = 'ja' + break + case /^zh-CN/i.test(locale): + locale = 'zh-cn' + break + case /^zh-TW/i.test(locale): + locale = 'zh-tw' + break + case /^zh.*/i.test(locale): + locale = 'zh-cn' + break + default: + locale = 'en' +} + const i18n = new VueI18n({ - locale: 'en', + locale: locale, fallbackLocale: 'en', messages: { 'en': en, diff --git a/assets/src/store/mutations.js b/assets/src/store/mutations.js index 36251041..881850ee 100644 --- a/assets/src/store/mutations.js +++ b/assets/src/store/mutations.js @@ -27,8 +27,34 @@ const mutations = { setLoading: (state, value) => { state.loading = value }, setReload: (state, value) => { state.reload = value }, setUser: (state, value) => { - moment.locale(value.locale) - i18n.locale = value.locale + let locale = (value.locale || navigator.language || navigator.browserLangugae).toLowerCase() + switch (true) { + case /^en.*/i.test(locale): + locale = 'en' + break + case /^fr.*/i.test(locale): + locale = 'fr' + break + case /^pt.*/i.test(locale): + locale = 'pr' + break + case /^ja.*/i.test(locale): + locale = 'ja' + break + case /^zh-CN/i.test(locale): + locale = 'zh-cn' + break + case /^zh-TW/i.test(locale): + locale = 'zh-tw' + break + case /^zh.*/i.test(locale): + locale = 'zh-cn' + break + default: + locale = 'en' + } + moment.locale(locale) + i18n.locale = locale state.user = value }, setCSS: (state, value) => (state.css = value), diff --git a/cmd/filemanager/main.go b/cmd/filemanager/main.go index de708bba..92112df8 100644 --- a/cmd/filemanager/main.go +++ b/cmd/filemanager/main.go @@ -64,7 +64,7 @@ func init() { flag.BoolVar(&allowPublish, "allow-publish", true, "Default allow publish option for new users") flag.BoolVar(&allowNew, "allow-new", true, "Default allow new option for new users") flag.BoolVar(&noAuth, "no-auth", false, "Disables authentication") - flag.StringVar(&locale, "locale", "en", "Default locale for new users") + flag.StringVar(&locale, "locale", "", "Default locale for new users, set it empty to enable auto detect from browser") flag.StringVar(&staticg, "staticgen", "", "Static Generator you want to enable") flag.BoolVarP(&showVer, "version", "v", false, "Show version") } @@ -81,7 +81,7 @@ func setupViper() { viper.SetDefault("AllowNew", true) viper.SetDefault("AllowPublish", true) viper.SetDefault("StaticGen", "") - viper.SetDefault("Locale", "en") + viper.SetDefault("Locale", "") viper.SetDefault("NoAuth", false) viper.SetDefault("BaseURL", "") viper.SetDefault("PrefixURL", "") diff --git a/filemanager.go b/filemanager.go index 04e04578..22d4116e 100644 --- a/filemanager.go +++ b/filemanager.go @@ -362,7 +362,7 @@ var DefaultUser = User{ Rules: []*Rule{}, CSS: "", Admin: true, - Locale: "en", + Locale: "", Scope: ".", FileSystem: fileutils.Dir("."), ViewMode: "mosaic",