summaryrefslogtreecommitdiffstats
path: root/lib/public
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2021-10-01 09:56:01 +0200
committerChristoph Wurst <christoph@winzerhof-wurst.at>2021-10-13 09:57:21 +0200
commit5b727fc7da346ce0b33905ac54114102ffa16f13 (patch)
tree17b4f223f67f734e66902344a391e1c9f74eb613 /lib/public
parent5b7764354c71f79b83394796cb947fef92dfd830 (diff)
downloadnextcloud-server-5b727fc7da346ce0b33905ac54114102ffa16f13.tar.gz
nextcloud-server-5b727fc7da346ce0b33905ac54114102ffa16f13.zip
Add L10n factory method for generic language heuristics
The existing `findLanguage` method tries its best to find the best language for the current users. For some tasks we don't want this but rather determine the most generic language for *another* user, e.g. when the current user trigger an email notifiaction to someone else. In this case the current user's language is a bad guess in many multi-language environments. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/public')
-rw-r--r--lib/public/L10N/IFactory.php35
1 files changed, 30 insertions, 5 deletions
diff --git a/lib/public/L10N/IFactory.php b/lib/public/L10N/IFactory.php
index 3fe212edb9c..69b7d2281ce 100644
--- a/lib/public/L10N/IFactory.php
+++ b/lib/public/L10N/IFactory.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -46,13 +49,35 @@ interface IFactory {
public function get($app, $lang = null, $locale = null);
/**
- * Find the best language
+ * Find the best language for the context of the current user
*
- * @param string|null $app App id or null for core
- * @return string language If nothing works it returns 'en'
+ * This method will try to find the most specific language based on info
+ * from the user who is logged into the current process and will fall
+ * back to system settings and heuristics otherwise.
+ *
+ * @param string|null $appId specify if you only want a language a specific app supports
+ *
+ * @return string language code, defaults to 'en' if no other matches are found
* @since 9.0.0
*/
- public function findLanguage($app = null);
+ public function findLanguage(?string $appId = null): string;
+
+ /**
+ * Try to find the best language for generic tasks
+ *
+ * This method will try to find the most generic language based on system
+ * settings, independent of the user logged into the current process. This
+ * is useful for tasks that are run for another user. E.g. the current user
+ * sends an email to someone else, then we don't want the current user's
+ * language to be picked but rather a instance-wide default that likely fits
+ * the target user
+ *
+ * @param string|null $appId specify if you only want a language a specific app supports
+ *
+ * @return string language code, defaults to 'en' if no other matches are found
+ * @since 23.0.0
+ */
+ public function findGenericLanguage(string $appId = null): string;
/**
* @param string|null $lang user language as default locale
@@ -78,7 +103,7 @@ interface IFactory {
* @return string[] an array of available languages
* @since 9.0.0
*/
- public function findAvailableLanguages($app = null);
+ public function findAvailableLanguages($app = null): array;
/**
* @return array an array of available