Skip to content

Commit

Permalink
fix: ja-JP locate missing in config (#2264)
Browse files Browse the repository at this point in the history
Co-authored-by: Mr.Hope <mister-hope@outlook.com>
  • Loading branch information
unknowIfGuestInDream and Mister-Hope committed Oct 7, 2022
1 parent f4e98fc commit 81bfa6c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/shared/src/node/utils/dayjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { default as timezone } from "dayjs/plugin/timezone.js";
import { default as utc } from "dayjs/plugin/utc.js";
import { loadDeLocale } from "./de.js";
import { loadDeAtLocale } from "./de-at.js";

import { loadEnLocale } from "./en.js";
import { loadEsLocale } from "./es.js";
import { loadFrLocale } from "./fr.js";
Expand All @@ -17,6 +16,7 @@ import { loadUkLocale } from "./uk.js";
import { loadViLocale } from "./vi.js";
import { loadZhLocale } from "./zh.js";
import { loadZhTWLocale } from "./zh-tw.js";
import { loadJaLocale } from "./ja.js";

dayjs.extend(localizedFormat);
dayjs.extend(objectSupport);
Expand All @@ -36,6 +36,7 @@ loadUkLocale(dayjs);
loadViLocale(dayjs);
loadZhLocale(dayjs);
loadZhTWLocale(dayjs);
loadJaLocale(dayjs);

export const getLocale = (lang = "en"): string => {
const langcode = lang.toLowerCase();
Expand All @@ -55,6 +56,7 @@ export const getLocale = (lang = "en"): string => {
"vi",
"zh",
"zh-tw",
"ja",
].includes(langcode)
)
return langcode;
Expand All @@ -68,6 +70,7 @@ export const getLocale = (lang = "en"): string => {
if (langcode === "sk-sk") return "sk";
if (langcode === "vi-vn") return "vi";
if (langcode === "zh-cn") return "zh";
if (langcode === "ja-jp") return "ja";

console.warn(`${lang} locale missing in config`);

Expand Down
62 changes: 62 additions & 0 deletions packages/shared/src/node/utils/dayjs/ja.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Japanese [ja]
import type { default as dayjs } from "dayjs";
import type { Locale } from "./locale.js";

const locale: Locale = {
name: "ja-jp",
weekdays: "日曜日_月曜日_火曜日_水曜日_木曜日_金曜日_土曜日".split("_"),
weekdaysShort: "日曜_月曜_火曜_水曜_木曜_金曜_土曜".split("_"),
weekdaysMin: "日_月_火_水_木_金_土".split("_"),
months:
"一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月".split(
"_"
),
monthsShort: "1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月".split("_"),
ordinal: (n) => `${n}日`,
weekStart: 1,
yearStart: 4,
formats: {
LT: "HH:mm",
LTS: "HH:mm:ss",
L: "YYYY/MM/DD",
LL: "YYYY年M月D日",
LLL: "YYYY年M月D日Ah時mm分",
LLLL: "YYYY年M月D日ddddAh時mm分",
l: "YYYY/M/D",
ll: "YYYY年M月D日",
lll: "YYYY年M月D日 HH:mm",
llll: "YYYY年M月D日dddd HH:mm",
},
relativeTime: {
future: "%s以内",
past: "%s前",
s: "数秒",
m: "1 分",
mm: "%d 分",
h: "1 時間",
hh: "%d 時間",
d: "1 日",
dd: "%d 日",
M: "1 ヶ月",
MM: "%d ヶ月",
y: "1 年",
yy: "%d 年",
},
meridiem: (hour, minute) => {
const hm = hour * 100 + minute;

return hm < 600
? "朝"
: hm < 1200
? "午前"
: hm < 1800
? "午後"
: hm < 2000
? "晚"
: "夜";
},
};

export const loadJaLocale = (extendeddayjs: typeof dayjs): void => {
extendeddayjs.locale("ja", locale);
};

0 comments on commit 81bfa6c

Please sign in to comment.