tr.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import * as util from "../core/util.js";
  2. const Sizable = {
  3. string: { unit: "karakter", verb: "olmalı" },
  4. file: { unit: "bayt", verb: "olmalı" },
  5. array: { unit: "öğe", verb: "olmalı" },
  6. set: { unit: "öğe", verb: "olmalı" },
  7. };
  8. function getSizing(origin) {
  9. return Sizable[origin] ?? null;
  10. }
  11. export const parsedType = (data) => {
  12. const t = typeof data;
  13. switch (t) {
  14. case "number": {
  15. return Number.isNaN(data) ? "NaN" : "number";
  16. }
  17. case "object": {
  18. if (Array.isArray(data)) {
  19. return "array";
  20. }
  21. if (data === null) {
  22. return "null";
  23. }
  24. if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
  25. return data.constructor.name;
  26. }
  27. }
  28. }
  29. return t;
  30. };
  31. const Nouns = {
  32. regex: "girdi",
  33. email: "e-posta adresi",
  34. url: "URL",
  35. emoji: "emoji",
  36. uuid: "UUID",
  37. uuidv4: "UUIDv4",
  38. uuidv6: "UUIDv6",
  39. nanoid: "nanoid",
  40. guid: "GUID",
  41. cuid: "cuid",
  42. cuid2: "cuid2",
  43. ulid: "ULID",
  44. xid: "XID",
  45. ksuid: "KSUID",
  46. datetime: "ISO tarih ve saat",
  47. date: "ISO tarih",
  48. time: "ISO saat",
  49. duration: "ISO süre",
  50. ipv4: "IPv4 adresi",
  51. ipv6: "IPv6 adresi",
  52. cidrv4: "IPv4 aralığı",
  53. cidrv6: "IPv6 aralığı",
  54. base64: "base64 ile şifrelenmiş metin",
  55. base64url: "base64url ile şifrelenmiş metin",
  56. json_string: "JSON dizesi",
  57. e164: "E.164 sayısı",
  58. jwt: "JWT",
  59. template_literal: "Şablon dizesi",
  60. };
  61. const error = (issue) => {
  62. switch (issue.code) {
  63. case "invalid_type":
  64. return `Geçersiz değer: beklenen ${issue.expected}, alınan ${parsedType(issue.input)}`;
  65. case "invalid_value":
  66. if (issue.values.length === 1)
  67. return `Geçersiz değer: beklenen ${util.stringifyPrimitive(issue.values[0])}`;
  68. return `Geçersiz seçenek: aşağıdakilerden biri olmalı: ${util.joinValues(issue.values, "|")}`;
  69. case "too_big": {
  70. const adj = issue.inclusive ? "<=" : "<";
  71. const sizing = getSizing(issue.origin);
  72. if (sizing)
  73. return `Çok büyük: beklenen ${issue.origin ?? "değer"} ${adj}${issue.maximum.toString()} ${sizing.unit ?? "öğe"}`;
  74. return `Çok büyük: beklenen ${issue.origin ?? "değer"} ${adj}${issue.maximum.toString()}`;
  75. }
  76. case "too_small": {
  77. const adj = issue.inclusive ? ">=" : ">";
  78. const sizing = getSizing(issue.origin);
  79. if (sizing)
  80. return `Çok küçük: beklenen ${issue.origin} ${adj}${issue.minimum.toString()} ${sizing.unit}`;
  81. return `Çok küçük: beklenen ${issue.origin} ${adj}${issue.minimum.toString()}`;
  82. }
  83. case "invalid_format": {
  84. const _issue = issue;
  85. if (_issue.format === "starts_with")
  86. return `Geçersiz metin: "${_issue.prefix}" ile başlamalı`;
  87. if (_issue.format === "ends_with")
  88. return `Geçersiz metin: "${_issue.suffix}" ile bitmeli`;
  89. if (_issue.format === "includes")
  90. return `Geçersiz metin: "${_issue.includes}" içermeli`;
  91. if (_issue.format === "regex")
  92. return `Geçersiz metin: ${_issue.pattern} desenine uymalı`;
  93. return `Geçersiz ${Nouns[_issue.format] ?? issue.format}`;
  94. }
  95. case "not_multiple_of":
  96. return `Geçersiz sayı: ${issue.divisor} ile tam bölünebilmeli`;
  97. case "unrecognized_keys":
  98. return `Tanınmayan anahtar${issue.keys.length > 1 ? "lar" : ""}: ${util.joinValues(issue.keys, ", ")}`;
  99. case "invalid_key":
  100. return `${issue.origin} içinde geçersiz anahtar`;
  101. case "invalid_union":
  102. return "Geçersiz değer";
  103. case "invalid_element":
  104. return `${issue.origin} içinde geçersiz değer`;
  105. default:
  106. return `Geçersiz değer`;
  107. }
  108. };
  109. export { error };
  110. export default function () {
  111. return {
  112. localeError: error,
  113. };
  114. }