mirror of
https://github.com/octoleo/syncthing.git
synced 2024-09-10 17:09:01 +00:00
Enable URL lang parameter for switching languages (fixes #1080)
This commit is contained in:
parent
c6041d2590
commit
f62812a8dc
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@ bin
|
|||||||
perfstats*.csv
|
perfstats*.csv
|
||||||
coverage.xml
|
coverage.xml
|
||||||
!gui/scripts/syncthing
|
!gui/scripts/syncthing
|
||||||
|
.DS_Store
|
||||||
|
@ -583,7 +583,7 @@ angular.module('syncthing.core')
|
|||||||
$scope.config.GUI = angular.copy($scope.tmpGUI);
|
$scope.config.GUI = angular.copy($scope.tmpGUI);
|
||||||
|
|
||||||
['ListenAddress', 'GlobalAnnServers'].forEach(function (key) {
|
['ListenAddress', 'GlobalAnnServers'].forEach(function (key) {
|
||||||
$scope.config.Options[key] = $scope.config.Options[key + "Str"].split(/[ ,]+/).map(function (x) {
|
$scope.config.Options[key] = $scope.config.Options[key + "Str"].split(/[ ,]+/).map(function (x) {
|
||||||
return x.trim();
|
return x.trim();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -918,11 +918,12 @@ angular.module('syncthing.core')
|
|||||||
var devices = $scope.folders[folderID].Devices
|
var devices = $scope.folders[folderID].Devices
|
||||||
for (var i = 0; i < devices.length; i++) {
|
for (var i = 0; i < devices.length; i++) {
|
||||||
if (devices[i].DeviceID == deviceCfg.DeviceID) {
|
if (devices[i].DeviceID == deviceCfg.DeviceID) {
|
||||||
folders.push(folderID)
|
folders.push(folderID);
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
folders.sort();
|
folders.sort();
|
||||||
return folders;
|
return folders;
|
||||||
};
|
};
|
||||||
|
@ -12,7 +12,7 @@ angular.module('syncthing.core')
|
|||||||
_availableLocales = locales;
|
_availableLocales = locales;
|
||||||
};
|
};
|
||||||
|
|
||||||
this.$get = ['$http', '$translate', function ($http, $translate) {
|
this.$get = ['$http', '$translate', '$location', function ($http, $translate, $location) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests the server in order to get the browser's requested locale strings.
|
* Requests the server in order to get the browser's requested locale strings.
|
||||||
@ -26,45 +26,50 @@ angular.module('syncthing.core')
|
|||||||
}
|
}
|
||||||
|
|
||||||
function autoConfigLocale() {
|
function autoConfigLocale() {
|
||||||
|
var params = $location.search();
|
||||||
|
|
||||||
return readBrowserLocales().success(function (langs) {
|
if(params.lang) {
|
||||||
// Find the first language in the list provided by the user's browser
|
$translate.use(params.lang);
|
||||||
// that is a prefix of a language we have available. That is, "en"
|
} else {
|
||||||
// sent by the browser will match "en" or "en-US", while "zh-TW" will
|
readBrowserLocales().success(function (langs) {
|
||||||
// match only "zh-TW" and not "zh-CN".
|
// Find the first language in the list provided by the user's browser
|
||||||
|
// that is a prefix of a language we have available. That is, "en"
|
||||||
|
// sent by the browser will match "en" or "en-US", while "zh-TW" will
|
||||||
|
// match only "zh-TW" and not "zh-CN".
|
||||||
|
|
||||||
var i,
|
var i,
|
||||||
lang,
|
lang,
|
||||||
matching;
|
matching,
|
||||||
|
locale = _defaultLocale;
|
||||||
|
|
||||||
for (i = 0; i < langs.length; i++) {
|
for (i = 0; i < langs.length; i++) {
|
||||||
lang = langs[i];
|
lang = langs[i];
|
||||||
|
|
||||||
if (lang.length < 2) {
|
if (lang.length < 2) {
|
||||||
continue;
|
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.length > lang.length) {
|
|
||||||
return possibleLang.indexOf(lang) === 0;
|
|
||||||
} else {
|
|
||||||
return lang.indexOf(possibleLang) === 0;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if (matching.length >= 1) {
|
matching = _availableLocales.filter(function (possibleLang) {
|
||||||
$translate.use(matching[0]);
|
// The langs returned by the /rest/langs call will be in lower
|
||||||
return;
|
// case. We compare to the lowercase version of the language
|
||||||
|
// code we have as well.
|
||||||
|
possibleLang = possibleLang.toLowerCase();
|
||||||
|
if (possibleLang.length > lang.length) {
|
||||||
|
return possibleLang.indexOf(lang) === 0;
|
||||||
|
} else {
|
||||||
|
return lang.indexOf(possibleLang) === 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (matching.length >= 1) {
|
||||||
|
locale = matching[0];
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// Fallback if nothing matched
|
||||||
// Fallback if nothing matched
|
$translate.use(locale);
|
||||||
$translate.use(_defaultLocale);
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function useLocale(language) {
|
function useLocale(language) {
|
||||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user