summaryrefslogtreecommitdiffstats
path: root/lib
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 /lib
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 'lib')
-rw-r--r--lib/base.php1
-rw-r--r--lib/private/template/functions.php16
-rw-r--r--lib/private/util.php22
-rw-r--r--lib/public/util.php9
4 files changed, 46 insertions, 2 deletions
diff --git a/lib/base.php b/lib/base.php
index 3d374f12f7d..3554911abb9 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -338,6 +338,7 @@ class OC {
OC_Util::addScript("jquery.ocdialog");
OC_Util::addScript("oc-dialogs");
OC_Util::addScript("js");
+ OC_Util::addScript("l10n");
OC_Util::addScript("octemplate");
OC_Util::addScript("eventsource");
OC_Util::addScript("config");
diff --git a/lib/private/template/functions.php b/lib/private/template/functions.php
index cbe751e59b5..8c94b7cf345 100644
--- a/lib/private/template/functions.php
+++ b/lib/private/template/functions.php
@@ -56,6 +56,22 @@ function style($app, $file) {
}
/**
+ * Shortcut for adding translations to a page
+ * @param string $app the appname
+ * @param string|string[] $file the filename,
+ * if an array is given it will add all styles
+ */
+function translation($app, $file) {
+ if(is_array($file)) {
+ foreach($file as $f) {
+ OC_Util::addStyle($app, $f);
+ }
+ } else {
+ OC_Util::addStyle($app, $file);
+ }
+}
+
+/**
* Shortcut for HTML imports
* @param string $app the appname
* @param string|string[] $file the path relative to the app's component folder,
diff --git a/lib/private/util.php b/lib/private/util.php
index 6cd982c222e..5105bb22931 100644
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -333,7 +333,7 @@ class OC_Util {
/**
* add a javascript file
*
- * @param string $application
+ * @param string $application application id
* @param string|null $file filename
* @return void
*/
@@ -350,9 +350,27 @@ class OC_Util {
}
/**
+ * add a translation JS file
+ *
+ * @param string $application application id
+ * @param string $languageCode language code, defaults to the current language
+ */
+ public static function addTranslations($application, $languageCode = null) {
+ if (is_null($languageCode)) {
+ $l = new \OC_L10N($application);
+ $languageCode = $l->getLanguageCode($application);
+ }
+ if (!empty($application)) {
+ self::$scripts[] = "$application/l10n/$languageCode";
+ } else {
+ self::$scripts[] = "js/$languageCode";
+ }
+ }
+
+ /**
* add a css file
*
- * @param string $application
+ * @param string $application application id
* @param string|null $file filename
* @return void
*/
diff --git a/lib/public/util.php b/lib/public/util.php
index 4c4a84af240..22ded1d0fc5 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -137,6 +137,15 @@ class Util {
}
/**
+ * Add a translation JS file
+ * @param string $application application id
+ * @param string $languageCode language code, defaults to the current locale
+ */
+ public static function addTranslations($application, $languageCode = null) {
+ \OC_Util::addTranslations($application, $languageCode);
+ }
+
+ /**
* Add a custom element to the header
* @param string $tag tag name of the element
* @param array $attributes array of attributes for the element