DisplayNames.hx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C)2005-2021 Haxe Foundation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. package js.lib.intl;
  23. /**
  24. The `Intl.DisplayNames` object enables the consistent translation of language,
  25. region and script display names.
  26. **/
  27. @:native("Intl.DisplayNames")
  28. extern class DisplayNames {
  29. /**
  30. Creates a new `Intl.DisplayNames` object.
  31. **/
  32. @:overload(function(?locales: Array<String>, ?options: DisplayNamesOptions): Void {})
  33. function new(?locales: String, ?options: DisplayNamesOptions);
  34. /**
  35. Receives a code and returns a string based on the locale and options
  36. provided when instantiating `Intl.DisplayNames`.
  37. **/
  38. function of(code: String): String;
  39. /**
  40. Returns a new object with properties reflecting the locale and formatting options
  41. computed during initialization of the object.
  42. **/
  43. function resolvedOptions(): DisplayNamesResolvedOptions;
  44. /**
  45. Returns an array containing those of the provided locales that are supported
  46. in display names without having to fall back to the runtime's default locale.
  47. **/
  48. @:overload(function(locales: Array<String>, ?options: DisplayNamesSupportedLocalesOfOptions): Array<String> {})
  49. static function supportedLocalesOf(locales: String, ?options: DisplayNamesSupportedLocalesOfOptions): Array<String>;
  50. }
  51. enum abstract DisplayNamesFallback(String) {
  52. var Code = "code";
  53. var None = "none";
  54. }
  55. typedef DisplayNamesOptions = {
  56. /**
  57. The fallback to use.
  58. The default is `Code`.
  59. **/
  60. var fallback: DisplayNamesFallback;
  61. /**
  62. The locale matching algorithm to use.
  63. The default is `BestFit`.
  64. **/
  65. var ?localeMatcher: LocaleMatcher;
  66. /**
  67. The formatting style to use.
  68. The default is `Long`.
  69. **/
  70. var ?style: DisplayNamesStyle;
  71. /**
  72. The type to use.
  73. The default is `Language`.
  74. **/
  75. var ?type: DisplayNamesType;
  76. }
  77. typedef DisplayNamesResolvedOptions = {
  78. /**
  79. The value provided for this property in the `options` argument of the constructor
  80. or the default value (`Code`).
  81. **/
  82. final fallback: DisplayNamesFallback;
  83. /**
  84. The BCP 47 language tag for the locale actually used.
  85. **/
  86. final locale: String;
  87. /**
  88. The value provided for this property in the `options` argument of the constructor
  89. or the default value (`Long`).
  90. **/
  91. final style: DisplayNamesStyle;
  92. /**
  93. The value provided for this property in the `options` argument of the constructor
  94. or the default value (`Language`).
  95. **/
  96. final type: DisplayNamesType;
  97. }
  98. enum abstract DisplayNamesStyle(String) {
  99. var Long = "long";
  100. var Narrow = "narrow";
  101. var Short = "short";
  102. }
  103. typedef DisplayNamesSupportedLocalesOfOptions = {
  104. /**
  105. The locale matching algorithm to use.
  106. The default is `BestFit`.
  107. */
  108. var ?localeMatcher: LocaleMatcher;
  109. }
  110. enum abstract DisplayNamesType(String) {
  111. var Currency = "currency";
  112. var Language = "language";
  113. var Region = "region";
  114. var Script = "script";
  115. }