You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IFactory.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  7. * @author Georg Ehrke <oc.list@georgehrke.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author John Molakvoæ <skjnldsv@protonmail.com>
  10. * @author Julius Härtl <jus@bitgrid.net>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Roeland Jago Douma <roeland@famdouma.nl>
  13. * @author Thomas Citharel <nextcloud@tcit.fr>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. namespace OCP\L10N;
  31. use OCP\IUser;
  32. /**
  33. * @since 8.2.0
  34. */
  35. interface IFactory {
  36. /**
  37. * Get a language instance
  38. *
  39. * @param string $app
  40. * @param string|null $lang
  41. * @param string|null $locale
  42. * @return \OCP\IL10N
  43. * @since 8.2.0
  44. */
  45. public function get($app, $lang = null, $locale = null);
  46. /**
  47. * Find the best language for the context of the current user
  48. *
  49. * This method will try to find the most specific language based on info
  50. * from the user who is logged into the current process and will fall
  51. * back to system settings and heuristics otherwise.
  52. *
  53. * @param string|null $appId specify if you only want a language a specific app supports
  54. *
  55. * @return string language code, defaults to 'en' if no other matches are found
  56. * @since 9.0.0
  57. */
  58. public function findLanguage(?string $appId = null): string;
  59. /**
  60. * Try to find the best language for generic tasks
  61. *
  62. * This method will try to find the most generic language based on system
  63. * settings, independent of the user logged into the current process. This
  64. * is useful for tasks that are run for another user. E.g. the current user
  65. * sends an email to someone else, then we don't want the current user's
  66. * language to be picked but rather a instance-wide default that likely fits
  67. * the target user
  68. *
  69. * @param string|null $appId specify if you only want a language a specific app supports
  70. *
  71. * @return string language code, defaults to 'en' if no other matches are found
  72. * @since 23.0.0
  73. */
  74. public function findGenericLanguage(string $appId = null): string;
  75. /**
  76. * @param string|null $lang user language as default locale
  77. * @return string locale If nothing works it returns 'en_US'
  78. * @since 14.0.0
  79. */
  80. public function findLocale($lang = null);
  81. /**
  82. * find the matching lang from the locale
  83. *
  84. * @param string $app
  85. * @param string $locale
  86. * @return null|string
  87. * @since 14.0.1
  88. */
  89. public function findLanguageFromLocale(string $app = 'core', string $locale = null);
  90. /**
  91. * Find all available languages for an app
  92. *
  93. * @param string|null $app App id or null for core
  94. * @return string[] an array of available languages
  95. * @since 9.0.0
  96. */
  97. public function findAvailableLanguages($app = null): array;
  98. /**
  99. * @return array an array of available
  100. * @since 14.0.0
  101. */
  102. public function findAvailableLocales();
  103. /**
  104. * @param string|null $app App id or null for core
  105. * @param string $lang
  106. * @return bool
  107. * @since 9.0.0
  108. */
  109. public function languageExists($app, $lang);
  110. /**
  111. * @param string $locale
  112. * @return bool
  113. * @since 14.0.0
  114. */
  115. public function localeExists($locale);
  116. /**
  117. * iterate through language settings (if provided) in this order:
  118. * 1. returns the forced language or:
  119. * 2. if applicable, the trunk of 1 (e.g. "fu" instead of "fu_BAR"
  120. * 3. returns the user language or:
  121. * 4. if applicable, the trunk of 3
  122. * 5. returns the system default language or:
  123. * 6. if applicable, the trunk of 5
  124. * 7+∞. returns 'en'
  125. *
  126. * Hint: in most cases findLanguage() suits you fine
  127. *
  128. * @since 14.0.0
  129. */
  130. public function getLanguageIterator(IUser $user = null): ILanguageIterator;
  131. /**
  132. * returns the common language and other languages in an
  133. * associative array
  134. *
  135. * @since 23.0.0
  136. */
  137. public function getLanguages(): array;
  138. /**
  139. * Return the language to use when sending something to a user
  140. *
  141. * @param IUser|null $user
  142. * @return string
  143. * @since 20.0.0
  144. */
  145. public function getUserLanguage(IUser $user = null): string;
  146. }