dromara / carbon

A simple, semantic and developer-friendly golang package for time.
https://pkg.go.dev/github.com/dromara/carbon/v2
MIT License
4.83k stars 242 forks source link

Fixed farsi translation issue (fixes #247) #248

Closed zumoshi closed 1 month ago

zumoshi commented 1 month ago

To make sure the same mistake won't happen again, I first converted the en.json file to use newlines instead of | using the following js snippet:

JSON.stringify(Object.entries(en).map(([name,data])=>({name,value:data.split('|')})))

Then translated it this way:

[
  {
    "name": "name",
    "value": [
      "Farsi"
    ]
  },
  {
    "name": "months",
    "value": [
      "ژانویه",
      "فوریه",
      "مارس",
      "آوریل",
      "مه",
      "ژوئن",
      "ژوئیه",
      "اوت",
      "سپتامبر",
      "اکتبر",
      "نوامبر",
      "دسامبر"
    ]
  },
  {
    "name": "short_months",
    "value": [
      "ژانویه",
      "فوریه",
      "مارس",
      "آوریل",
      "مه",
      "ژوئن",
      "ژوئیه",
      "اوت",
      "سپتامبر",
      "اکتبر",
      "نوامبر",
      "دسامبر"
    ]
  },
  {
    "name": "weeks",
    "value": [
      "یکشنبه",
      "دوشنبه",
      "سه‌شنبه",
      "چهارشنبه",
      "پنجشنبه",
      "جمعه",
      "شنبه"
    ]
  },
  {
    "name": "short_weeks",
    "value": [
      "یکشنبه",
      "دوشنبه",
      "سه‌شنبه",
      "چهارشنبه",
      "پنجشنبه",
      "جمعه",
      "شنبه"
    ]
  },
  {
    "name": "seasons",
    "value": [
      "بهار",
      "تابستان",
      "پاییز",
      "زمستان"
    ]
  },
  {
    "name": "constellations",
    "value": [
      "قوچ",
      "گاو نر",
      "دو پیکر",
      "خرچنگ",
      "شیر",
      "خوشه",
      "ترازو",
      "عقرب",
      "کماندار",
      "بز",
      "آبریز",
      "ماهی"
    ]
  },
  {
    "name": "year",
    "value": [
      "1 سال",
      "%d سال"
    ]
  },
  {
    "name": "month",
    "value": [
      "1 ماه",
      "%d ماه"
    ]
  },
  {
    "name": "week",
    "value": [
      "1 هفته",
      "%d هفته"
    ]
  },
  {
    "name": "day",
    "value": [
      "1 روز",
      "%d روز"
    ]
  },
  {
    "name": "hour",
    "value": [
      "1 ساعت",
      "%d ساعت"
    ]
  },
  {
    "name": "minute",
    "value": [
      "1 دقیقه",
      "%d دقیقه"
    ]
  },
  {
    "name": "second",
    "value": [
      "1 ثانیه",
      "%d ثانیه"
    ]
  },
  {
    "name": "now",
    "value": [
      "همین الان"
    ]
  },
  {
    "name": "ago",
    "value": [
      "%s پیش"
    ]
  },
  {
    "name": "from_now",
    "value": [
      "در %s"
    ]
  },
  {
    "name": "before",
    "value": [
      "%s قبل"
    ]
  },
  {
    "name": "after",
    "value": [
      "%s بعد"
    ]
  }
]

Then converted it back using:

JSON.stringify(x.reduce((a,e)=>(a[e.name]=e.value.join('|'),a), {}))

from the diff it seems there were more issues with order of month/days as well. in general I don't recommend merging values and using non-standard separators. this could've been avoided if the format defined months as an array and used separate keys for one vs many cases.

zumoshi commented 1 month ago

the issue number in the title doesn't seem to be picked up, so: fixes #247

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.00%. Comparing base (89406e3) to head (0a3eff6). Report is 2 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #248 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 22 22 Lines 2380 2380 ========================================= Hits 2380 2380 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

gouguoyin commented 1 month ago

Thank you for your contribution