summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-15 14:44:48 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-15 14:44:48 +0200
commit01d6e6a3df56008d6fe684720e5be6de5f3ef7b2 (patch)
tree3c2b1c383ae58b585478eebcf265b1ece34b7fa7 /js
parentcdbafe0555fae50d7ab99f0c95573d2c3cacb97b (diff)
show real date on hover, more robust check for language support for relative dates
Diffstat (limited to 'js')
-rw-r--r--js/app/services/language.coffee63
-rw-r--r--js/public/app.js18
-rw-r--r--js/tests/services/languageSpec.coffee62
3 files changed, 134 insertions, 9 deletions
diff --git a/js/app/services/language.coffee b/js/app/services/language.coffee
index ac46b0bc4..c8b93cc06 100644
--- a/js/app/services/language.coffee
+++ b/js/app/services/language.coffee
@@ -26,10 +26,71 @@ angular.module('News').factory 'Language', ->
constructor: ->
@_language = 'en'
+ @_langs = [
+ 'ar-ma'
+ 'ar'
+ 'bg'
+ 'ca'
+ 'cs'
+ 'cv'
+ 'da'
+ 'de'
+ 'el'
+ 'en-ca'
+ 'en-gb'
+ 'eo'
+ 'es'
+ 'et'
+ 'eu'
+ 'fi'
+ 'fr-ca'
+ 'fr'
+ 'gl'
+ 'he'
+ 'hi'
+ 'hu'
+ 'id'
+ 'is'
+ 'it'
+ 'ja'
+ 'ka'
+ 'ko'
+ 'lv'
+ 'ms-my'
+ 'nb'
+ 'ne'
+ 'nl'
+ 'pl'
+ 'pt-br'
+ 'pt'
+ 'ro'
+ 'ru'
+ 'sk'
+ 'sl'
+ 'sv'
+ 'th'
+ 'tr'
+ 'tzm-la'
+ 'tzm'
+ 'uk'
+ 'zh-cn'
+ 'zh-tw'
+ ]
handle: (data) ->
- @_language = data.split('_')[0]
+ # fix broken server locales
+ data = data.replace('_', '-').toLowerCase()
+
+ # check if the first part is available, if so use this
+ if not (data in @_langs)
+ data = data.split('-')[0]
+
+ # if its not available default to english
+ if not (data in @_langs)
+ data = 'en'
+
+ @_language = data
getLanguage: ->
diff --git a/js/public/app.js b/js/public/app.js
index f9ae29d48..df081ffb7 100644
--- a/js/public/app.js
+++ b/js/public/app.js
@@ -1399,16 +1399,26 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
(function() {
+ var __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+
angular.module('News').factory('Language', function() {
var Language;
Language = (function() {
function Language() {
this._language = 'en';
+ this._langs = ['ar-ma', 'ar', 'bg', 'ca', 'cs', 'cv', 'da', 'de', 'el', 'en-ca', 'en-gb', 'eo', 'es', 'et', 'eu', 'fi', 'fr-ca', 'fr', 'gl', 'he', 'hi', 'hu', 'id', 'is', 'it', 'ja', 'ka', 'ko', 'lv', 'ms-my', 'nb', 'ne', 'nl', 'pl', 'pt-br', 'pt', 'ro', 'ru', 'sk', 'sl', 'sv', 'th', 'tr', 'tzm-la', 'tzm', 'uk', 'zh-cn', 'zh-tw'];
}
Language.prototype.handle = function(data) {
- return this._language = data.split('_')[0];
+ data = data.replace('_', '-').toLowerCase();
+ if (!(__indexOf.call(this._langs, data) >= 0)) {
+ data = data.split('-')[0];
+ }
+ if (!(__indexOf.call(this._langs, data) >= 0)) {
+ data = 'en';
+ }
+ return this._language = data;
};
Language.prototype.getLanguage = function() {
@@ -1937,12 +1947,6 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
}).call(this);
// Generated by CoffeeScript 1.6.2
-(function() {
-
-
-}).call(this);
-
-// Generated by CoffeeScript 1.6.2
/*
ownCloud - News
diff --git a/js/tests/services/languageSpec.coffee b/js/tests/services/languageSpec.coffee
index 958b91ad1..c2d8b4cfc 100644
--- a/js/tests/services/languageSpec.coffee
+++ b/js/tests/services/languageSpec.coffee
@@ -37,7 +37,67 @@ describe 'Language', ->
@Language.handle(@data)
expect(@Language.getLanguage()).toBe('de')
- it 'should only set the first part of the language', =>
+ it 'should only set the first part of the language if not available', =>
@Language.handle 'de_DE'
expect(@Language.getLanguage()).toBe('de')
+ it 'should default to en', =>
+ @Language.handle 'dse_DEst'
+ expect(@Language.getLanguage()).toBe('en')
+
+
+ it 'should support languages', =>
+ langs = [
+ 'ar-ma'
+ 'ar'
+ 'bg'
+ 'ca'
+ 'cs'
+ 'cv'
+ 'da'
+ 'de'
+ 'el'
+ 'en-ca'
+ 'en-gb'
+ 'eo'
+ 'es'
+ 'et'
+ 'eu'
+ 'fi'
+ 'fr-ca'
+ 'fr'
+ 'gl'
+ 'he'
+ 'hi'
+ 'hu'
+ 'id'
+ 'is'
+ 'it'
+ 'ja'
+ 'ka'
+ 'ko'
+ 'lv'
+ 'ms-my'
+ 'nb'
+ 'ne'
+ 'nl'
+ 'pl'
+ 'pt-br'
+ 'pt'
+ 'ro'
+ 'ru'
+ 'sk'
+ 'sl'
+ 'sv'
+ 'th'
+ 'tr'
+ 'tzm-la'
+ 'tzm'
+ 'uk'
+ 'zh-cn'
+ 'zh-tw'
+ ]
+
+ for lang in langs
+ @Language.handle lang
+ expect(@Language.getLanguage()).toBe(lang) \ No newline at end of file