summaryrefslogtreecommitdiffstats
path: root/core/js/tests
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-10-17 19:47:37 +0200
committerThomas Müller <thomas.mueller@tmit.eu>2014-10-29 10:09:12 +0100
commitec1a73fab9aa6b71b502ee45f4d0dd4f20661930 (patch)
treef60269f9999cc94b66043b8ac87ac92f9014b4ed /core/js/tests
parentf67123c5a498e45a08900987b10779c7c60af601 (diff)
downloadnextcloud-server-ec1a73fab9aa6b71b502ee45f4d0dd4f20661930.tar.gz
nextcloud-server-ec1a73fab9aa6b71b502ee45f4d0dd4f20661930.zip
Added OC.L10N namespace with translation functions
Added addTranslations and fixed de.js file Fixed de.js to use OC.L10N.register() and use to correct expected format. Added JS unit tests for OC.L10N class Include translations JS script for all apps
Diffstat (limited to 'core/js/tests')
-rw-r--r--core/js/tests/specHelper.js9
-rw-r--r--core/js/tests/specs/l10nSpec.js101
2 files changed, 101 insertions, 9 deletions
diff --git a/core/js/tests/specHelper.js b/core/js/tests/specHelper.js
index b62a0efe40d..4111b6763d9 100644
--- a/core/js/tests/specHelper.js
+++ b/core/js/tests/specHelper.js
@@ -113,15 +113,6 @@ window.isPhantom = /phantom/i.test(navigator.userAgent);
// must use fake responses for expected calls
fakeServer = sinon.fakeServer.create();
- // return fake translations as they might be requested for many test runs
- fakeServer.respondWith(/\/index.php\/core\/ajax\/translations.php$/, [
- 200, {
- "Content-Type": "application/json"
- },
- '{"data": [], "plural_form": "nplurals=2; plural=(n != 1);"}'
- ]
- );
-
// make it globally available, so that other tests can define
// custom responses
window.fakeServer = fakeServer;
diff --git a/core/js/tests/specs/l10nSpec.js b/core/js/tests/specs/l10nSpec.js
new file mode 100644
index 00000000000..d5b0363ea38
--- /dev/null
+++ b/core/js/tests/specs/l10nSpec.js
@@ -0,0 +1,101 @@
+/**
+ * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+describe('OC.L10N tests', function() {
+ var TEST_APP = 'jsunittestapp';
+
+ afterEach(function() {
+ delete OC.L10N._bundles[TEST_APP];
+ });
+
+ describe('text translation', function() {
+ beforeEach(function() {
+ OC.L10N.register(TEST_APP, {
+ 'Hello world!': 'Hallo Welt!',
+ 'Hello {name}, the weather is {weather}': 'Hallo {name}, das Wetter ist {weather}',
+ 'sunny': 'sonnig'
+ });
+ });
+ it('returns untranslated text when no bundle exists', function() {
+ delete OC.L10N._bundles[TEST_APP];
+ expect(t(TEST_APP, 'unknown text')).toEqual('unknown text');
+ });
+ it('returns untranslated text when no key exists', function() {
+ expect(t(TEST_APP, 'unknown text')).toEqual('unknown text');
+ });
+ it('returns translated text when key exists', function() {
+ expect(t(TEST_APP, 'Hello world!')).toEqual('Hallo Welt!');
+ });
+ it('returns translated text with placeholder', function() {
+ expect(
+ t(TEST_APP, 'Hello {name}, the weather is {weather}', {name: 'Steve', weather: t(TEST_APP, 'sunny')})
+ ).toEqual('Hallo Steve, das Wetter ist sonnig');
+ });
+ });
+ describe('plurals', function() {
+ function checkPlurals() {
+ expect(
+ n(TEST_APP, 'download %n file', 'download %n files', 0)
+ ).toEqual('0 Dateien herunterladen');
+ expect(
+ n(TEST_APP, 'download %n file', 'download %n files', 1)
+ ).toEqual('1 Datei herunterladen');
+ expect(
+ n(TEST_APP, 'download %n file', 'download %n files', 2)
+ ).toEqual('2 Dateien herunterladen');
+ expect(
+ n(TEST_APP, 'download %n file', 'download %n files', 1024)
+ ).toEqual('1024 Dateien herunterladen');
+ }
+
+ it('generates plural for default text when translation does not exist', function() {
+ OC.L10N.register(TEST_APP, {
+ });
+ expect(
+ n(TEST_APP, 'download %n file', 'download %n files', 0)
+ ).toEqual('download 0 files');
+ expect(
+ n(TEST_APP, 'download %n file', 'download %n files', 1)
+ ).toEqual('download 1 file');
+ expect(
+ n(TEST_APP, 'download %n file', 'download %n files', 2)
+ ).toEqual('download 2 files');
+ expect(
+ n(TEST_APP, 'download %n file', 'download %n files', 1024)
+ ).toEqual('download 1024 files');
+ });
+ it('generates plural with default function when no forms specified', function() {
+ OC.L10N.register(TEST_APP, {
+ '_download %n file_::_download %n files_':
+ ['%n Datei herunterladen', '%n Dateien herunterladen']
+ });
+ checkPlurals();
+ });
+ it('generates plural with generated function when forms is specified', function() {
+ OC.L10N.register(TEST_APP, {
+ '_download %n file_::_download %n files_':
+ ['%n Datei herunterladen', '%n Dateien herunterladen']
+ }, 'nplurals=2; plural=(n != 1);');
+ checkPlurals();
+ });
+ it('generates plural with function when forms is specified as function', function() {
+ OC.L10N.register(TEST_APP, {
+ '_download %n file_::_download %n files_':
+ ['%n Datei herunterladen', '%n Dateien herunterladen']
+ }, function(n) {
+ return {
+ nplurals: 2,
+ plural: (n !== 1) ? 1 : 0
+ };
+ });
+ checkPlurals();
+ });
+ });
+});