IFactory.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  6. * SPDX-License-Identifier: AGPL-3.0-only
  7. */
  8. namespace OCP\L10N;
  9. use OCP\IUser;
  10. /**
  11. * @since 8.2.0
  12. */
  13. interface IFactory {
  14. /**
  15. * Get a language instance
  16. *
  17. * @param string $app
  18. * @param string|null $lang
  19. * @param string|null $locale
  20. * @return \OCP\IL10N
  21. * @since 8.2.0
  22. */
  23. public function get($app, $lang = null, $locale = null);
  24. /**
  25. * Find the best language for the context of the current user
  26. *
  27. * This method will try to find the most specific language based on info
  28. * from the user who is logged into the current process and will fall
  29. * back to system settings and heuristics otherwise.
  30. *
  31. * @param string|null $appId specify if you only want a language a specific app supports
  32. *
  33. * @return string language code, defaults to 'en' if no other matches are found
  34. * @since 9.0.0
  35. */
  36. public function findLanguage(?string $appId = null): string;
  37. /**
  38. * Try to find the best language for generic tasks
  39. *
  40. * This method will try to find the most generic language based on system
  41. * settings, independent of the user logged into the current process. This
  42. * is useful for tasks that are run for another user. E.g. the current user
  43. * sends an email to someone else, then we don't want the current user's
  44. * language to be picked but rather a instance-wide default that likely fits
  45. * the target user
  46. *
  47. * @param string|null $appId specify if you only want a language a specific app supports
  48. *
  49. * @return string language code, defaults to 'en' if no other matches are found
  50. * @since 23.0.0
  51. */
  52. public function findGenericLanguage(?string $appId = null): string;
  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): array;
  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. * 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. /**
  110. * returns the common language and other languages in an
  111. * associative array
  112. *
  113. * @since 23.0.0
  114. */
  115. public function getLanguages(): array;
  116. /**
  117. * Return the language to use when sending something to a user
  118. *
  119. * @param IUser|null $user
  120. * @return string
  121. * @since 20.0.0
  122. */
  123. public function getUserLanguage(?IUser $user = null): string;
  124. }