1
0

IFactory.php 3.0 KB

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