IFactory.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. * @return \OCP\IL10N
  34. * @since 8.2.0
  35. */
  36. public function get($app, $lang = null);
  37. /**
  38. * Find the best language
  39. *
  40. * @param string|null $app App id or null for core
  41. * @return string language If nothing works it returns 'en'
  42. * @since 9.0.0
  43. */
  44. public function findLanguage($app = null);
  45. /**
  46. * @param string|null $lang user language as default locale
  47. * @return string locale If nothing works it returns 'en_US'
  48. * @since 14.0.0
  49. */
  50. public function findLocale($lang = null);
  51. /**
  52. * find the matching lang from the locale
  53. *
  54. * @param string $app
  55. * @param string $locale
  56. * @return null|string
  57. * @since 14.0.1
  58. */
  59. public function findLanguageFromLocale(string $app = 'core', string $locale = null);
  60. /**
  61. * Find all available languages for an app
  62. *
  63. * @param string|null $app App id or null for core
  64. * @return string[] an array of available languages
  65. * @since 9.0.0
  66. */
  67. public function findAvailableLanguages($app = null);
  68. /**
  69. * @return array an array of available
  70. * @since 14.0.0
  71. */
  72. public function findAvailableLocales();
  73. /**
  74. * @param string|null $app App id or null for core
  75. * @param string $lang
  76. * @return bool
  77. * @since 9.0.0
  78. */
  79. public function languageExists($app, $lang);
  80. /**
  81. * @param string $locale
  82. * @return bool
  83. * @since 14.0.0
  84. */
  85. public function localeExists($locale);
  86. /**
  87. * Creates a function from the plural string
  88. *
  89. * @param string $string
  90. * @return string Unique function name
  91. * @since 14.0.0
  92. */
  93. public function createPluralFunction($string);
  94. /**
  95. * iterate through language settings (if provided) in this order:
  96. * 1. returns the forced language or:
  97. * 2. if applicable, the trunk of 1 (e.g. "fu" instead of "fu_BAR"
  98. * 3. returns the user language or:
  99. * 4. if applicable, the trunk of 3
  100. * 5. returns the system default language or:
  101. * 6. if applicable, the trunk of 5
  102. * 7+∞. returns 'en'
  103. *
  104. * Hint: in most cases findLanguage() suits you fine
  105. *
  106. * @since 14.0.0
  107. */
  108. public function getLanguageIterator(IUser $user = null): ILanguageIterator;
  109. }