formatDistance.mjs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. const formatDistanceLocale = {
  2. lessThanXSeconds: {
  3. past: "{{count}} წამზე ნაკლები ხნის წინ",
  4. present: "{{count}} წამზე ნაკლები",
  5. future: "{{count}} წამზე ნაკლებში",
  6. },
  7. xSeconds: {
  8. past: "{{count}} წამის წინ",
  9. present: "{{count}} წამი",
  10. future: "{{count}} წამში",
  11. },
  12. halfAMinute: {
  13. past: "ნახევარი წუთის წინ",
  14. present: "ნახევარი წუთი",
  15. future: "ნახევარი წუთში",
  16. },
  17. lessThanXMinutes: {
  18. past: "{{count}} წუთზე ნაკლები ხნის წინ",
  19. present: "{{count}} წუთზე ნაკლები",
  20. future: "{{count}} წუთზე ნაკლებში",
  21. },
  22. xMinutes: {
  23. past: "{{count}} წუთის წინ",
  24. present: "{{count}} წუთი",
  25. future: "{{count}} წუთში",
  26. },
  27. aboutXHours: {
  28. past: "დაახლოებით {{count}} საათის წინ",
  29. present: "დაახლოებით {{count}} საათი",
  30. future: "დაახლოებით {{count}} საათში",
  31. },
  32. xHours: {
  33. past: "{{count}} საათის წინ",
  34. present: "{{count}} საათი",
  35. future: "{{count}} საათში",
  36. },
  37. xDays: {
  38. past: "{{count}} დღის წინ",
  39. present: "{{count}} დღე",
  40. future: "{{count}} დღეში",
  41. },
  42. aboutXWeeks: {
  43. past: "დაახლოებით {{count}} კვირას წინ",
  44. present: "დაახლოებით {{count}} კვირა",
  45. future: "დაახლოებით {{count}} კვირაში",
  46. },
  47. xWeeks: {
  48. past: "{{count}} კვირას კვირა",
  49. present: "{{count}} კვირა",
  50. future: "{{count}} კვირაში",
  51. },
  52. aboutXMonths: {
  53. past: "დაახლოებით {{count}} თვის წინ",
  54. present: "დაახლოებით {{count}} თვე",
  55. future: "დაახლოებით {{count}} თვეში",
  56. },
  57. xMonths: {
  58. past: "{{count}} თვის წინ",
  59. present: "{{count}} თვე",
  60. future: "{{count}} თვეში",
  61. },
  62. aboutXYears: {
  63. past: "დაახლოებით {{count}} წლის წინ",
  64. present: "დაახლოებით {{count}} წელი",
  65. future: "დაახლოებით {{count}} წელში",
  66. },
  67. xYears: {
  68. past: "{{count}} წლის წინ",
  69. present: "{{count}} წელი",
  70. future: "{{count}} წელში",
  71. },
  72. overXYears: {
  73. past: "{{count}} წელზე მეტი ხნის წინ",
  74. present: "{{count}} წელზე მეტი",
  75. future: "{{count}} წელზე მეტი ხნის შემდეგ",
  76. },
  77. almostXYears: {
  78. past: "თითქმის {{count}} წლის წინ",
  79. present: "თითქმის {{count}} წელი",
  80. future: "თითქმის {{count}} წელში",
  81. },
  82. };
  83. export const formatDistance = (token, count, options) => {
  84. let result;
  85. const tokenValue = formatDistanceLocale[token];
  86. if (typeof tokenValue === "string") {
  87. result = tokenValue;
  88. } else if (
  89. options?.addSuffix &&
  90. options.comparison &&
  91. options.comparison > 0
  92. ) {
  93. result = tokenValue.future.replace("{{count}}", String(count));
  94. } else if (options?.addSuffix) {
  95. result = tokenValue.past.replace("{{count}}", String(count));
  96. } else {
  97. result = tokenValue.present.replace("{{count}}", String(count));
  98. }
  99. return result;
  100. };