2015-08-27 07:14:50 -04:00
|
|
|
<?php
|
2021-10-01 03:56:01 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2015-08-27 07:14:50 -04:00
|
|
|
/**
|
2016-01-12 09:02:16 -05:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
2016-07-21 11:07:57 -04:00
|
|
|
*
|
2019-12-03 13:57:53 -05:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2016-07-21 11:07:57 -04:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2021-06-04 15:52:51 -04:00
|
|
|
* @author John Molakvoæ <skjnldsv@protonmail.com>
|
2019-12-03 13:57:53 -05:00
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2020-03-31 04:49:10 -04:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2016-07-21 11:07:57 -04:00
|
|
|
*
|
2015-08-27 07:14:50 -04:00
|
|
|
* @license AGPL-3.0
|
|
|
|
|
*
|
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 13:57:53 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-08-27 07:14:50 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2021-10-14 04:05:17 -04:00
|
|
|
|
2015-08-27 07:14:50 -04:00
|
|
|
namespace OCP\L10N;
|
|
|
|
|
|
2018-07-04 18:41:59 -04:00
|
|
|
use OCP\IUser;
|
|
|
|
|
|
2015-08-28 09:46:55 -04:00
|
|
|
/**
|
|
|
|
|
* @since 8.2.0
|
|
|
|
|
*/
|
2015-08-27 07:14:50 -04:00
|
|
|
interface IFactory {
|
|
|
|
|
/**
|
|
|
|
|
* Get a language instance
|
|
|
|
|
*
|
|
|
|
|
* @param string $app
|
|
|
|
|
* @param string|null $lang
|
2018-12-07 10:27:31 -05:00
|
|
|
* @param string|null $locale
|
2015-08-27 07:14:50 -04:00
|
|
|
* @return \OCP\IL10N
|
2015-08-28 09:46:55 -04:00
|
|
|
* @since 8.2.0
|
2015-08-27 07:14:50 -04:00
|
|
|
*/
|
2018-12-07 10:27:31 -05:00
|
|
|
public function get($app, $lang = null, $locale = null);
|
2016-01-15 04:04:41 -05:00
|
|
|
|
2016-01-15 05:09:37 -05:00
|
|
|
/**
|
2021-10-01 03:56:01 -04:00
|
|
|
* Find the best language for the context of the current user
|
2016-01-15 05:09:37 -05:00
|
|
|
*
|
2021-10-01 03:56:01 -04:00
|
|
|
* 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
|
2016-01-15 05:09:37 -05:00
|
|
|
* @since 9.0.0
|
|
|
|
|
*/
|
2021-10-01 03:56:01 -04:00
|
|
|
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;
|
2016-01-15 05:09:37 -05:00
|
|
|
|
2017-07-17 03:49:58 -04:00
|
|
|
/**
|
|
|
|
|
* @param string|null $lang user language as default locale
|
|
|
|
|
* @return string locale If nothing works it returns 'en_US'
|
2018-06-28 11:37:16 -04:00
|
|
|
* @since 14.0.0
|
2017-07-17 03:49:58 -04:00
|
|
|
*/
|
|
|
|
|
public function findLocale($lang = null);
|
|
|
|
|
|
2018-09-10 04:19:49 -04:00
|
|
|
/**
|
|
|
|
|
* find the matching lang from the locale
|
|
|
|
|
*
|
2018-09-10 04:45:18 -04:00
|
|
|
* @param string $app
|
2018-09-10 04:19:49 -04:00
|
|
|
* @param string $locale
|
|
|
|
|
* @return null|string
|
2018-09-19 10:02:09 -04:00
|
|
|
* @since 14.0.1
|
2018-09-10 04:19:49 -04:00
|
|
|
*/
|
2018-09-10 05:17:03 -04:00
|
|
|
public function findLanguageFromLocale(string $app = 'core', string $locale = null);
|
2018-09-10 04:19:49 -04:00
|
|
|
|
2016-01-15 04:04:41 -05:00
|
|
|
/**
|
|
|
|
|
* Find all available languages for an app
|
|
|
|
|
*
|
|
|
|
|
* @param string|null $app App id or null for core
|
|
|
|
|
* @return string[] an array of available languages
|
|
|
|
|
* @since 9.0.0
|
|
|
|
|
*/
|
2021-10-01 03:56:01 -04:00
|
|
|
public function findAvailableLanguages($app = null): array;
|
2016-01-15 04:27:09 -05:00
|
|
|
|
2017-07-07 05:17:54 -04:00
|
|
|
/**
|
|
|
|
|
* @return array an array of available
|
2018-06-29 02:02:50 -04:00
|
|
|
* @since 14.0.0
|
2017-07-07 05:17:54 -04:00
|
|
|
*/
|
|
|
|
|
public function findAvailableLocales();
|
|
|
|
|
|
2016-01-15 04:27:09 -05:00
|
|
|
/**
|
|
|
|
|
* @param string|null $app App id or null for core
|
|
|
|
|
* @param string $lang
|
|
|
|
|
* @return bool
|
|
|
|
|
* @since 9.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function languageExists($app, $lang);
|
2017-07-07 05:17:54 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $locale
|
|
|
|
|
* @return bool
|
2018-06-28 11:37:16 -04:00
|
|
|
* @since 14.0.0
|
2017-07-07 05:17:54 -04:00
|
|
|
*/
|
|
|
|
|
public function localeExists($locale);
|
|
|
|
|
|
2018-06-26 11:25:37 -04:00
|
|
|
/**
|
|
|
|
|
* iterate through language settings (if provided) in this order:
|
|
|
|
|
* 1. returns the forced language or:
|
2018-07-04 18:41:59 -04:00
|
|
|
* 2. if applicable, the trunk of 1 (e.g. "fu" instead of "fu_BAR"
|
|
|
|
|
* 3. returns the user language or:
|
|
|
|
|
* 4. if applicable, the trunk of 3
|
|
|
|
|
* 5. returns the system default language or:
|
|
|
|
|
* 6. if applicable, the trunk of 5
|
|
|
|
|
* 7+∞. returns 'en'
|
|
|
|
|
*
|
|
|
|
|
* Hint: in most cases findLanguage() suits you fine
|
|
|
|
|
*
|
2018-06-26 11:25:37 -04:00
|
|
|
* @since 14.0.0
|
|
|
|
|
*/
|
2018-07-04 18:41:59 -04:00
|
|
|
public function getLanguageIterator(IUser $user = null): ILanguageIterator;
|
2020-06-22 11:38:58 -04:00
|
|
|
|
2021-10-14 04:05:17 -04:00
|
|
|
/**
|
|
|
|
|
* returns the common language and other languages in an
|
|
|
|
|
* associative array
|
|
|
|
|
*
|
|
|
|
|
* @since 23.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function getLanguages(): array;
|
|
|
|
|
|
2020-06-22 11:38:58 -04:00
|
|
|
/**
|
|
|
|
|
* Return the language to use when sending something to a user
|
|
|
|
|
*
|
|
|
|
|
* @param IUser|null $user
|
|
|
|
|
* @return string
|
|
|
|
|
* @since 20.0.0
|
|
|
|
|
*/
|
|
|
|
|
public function getUserLanguage(IUser $user = null): string;
|
2015-08-27 07:14:50 -04:00
|
|
|
}
|