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.

138 lines
3.5 KiB

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