메인 μ½˜ν…μΈ λ‘œ κ±΄λ„ˆλ›°κΈ°
SonamuλŠ” λ‹€κ΅­μ–΄ λ©”μ‹œμ§€ μž‘μ„±μ„ λ•λŠ” 헬퍼 ν•¨μˆ˜λ“€μ„ μ œκ³΅ν•©λ‹ˆλ‹€.

josa - ν•œκ΅­μ–΄ 쑰사 처리

josa() ν•¨μˆ˜λŠ” μ•ž λ‹¨μ–΄μ˜ λ°›μΉ¨ μœ λ¬΄μ— 따라 μ μ ˆν•œ 쑰사λ₯Ό μ„ νƒν•©λ‹ˆλ‹€:
import { josa } from "sonamu/dict";

josa("μ‚¬λžŒ", "μ€λŠ”"); // "μ‚¬λžŒμ€"
josa("λ‚˜", "μ€λŠ”"); // "λ‚˜λŠ”"

josa("λ¬Ό", "이가"); // "물이"
josa("λ°”λ‹€", "이가"); // "λ°”λ‹€κ°€"

josa("λ°₯", "을λ₯Ό"); // "λ°₯을"
josa("컀피", "을λ₯Ό"); // "컀피λ₯Ό"

josa("λΉ΅", "과와"); // "λΉ΅κ³Ό"
josa("우유", "과와"); // "μš°μœ μ™€"

josa("μ§‘", "으둜"); // "μ§‘μœΌλ‘œ"
josa("학ꡐ", "으둜"); // "ν•™κ΅λ‘œ"

μ§€μ›ν•˜λŠ” 쑰사

쑰사받침 μžˆμ„ λ•Œλ°›μΉ¨ 없을 λ•Œ
μ€λŠ”μ€λŠ”
이가이가
을λ₯Όμ„λ₯Ό
과와과와
으둜으둜둜

λ”•μ…”λ„ˆλ¦¬μ—μ„œ μ‚¬μš©

// ko.ts
import { josa } from "sonamu/dict";

export default {
  "validation.required": (field: string) => `${josa(field, "μ€λŠ”")} ν•„μˆ˜μž…λ‹ˆλ‹€`,
  "validation.duplicate": (field: string) => `이미 μ‚¬μš©μ€‘μΈ ${josa(field, "이가")} μžˆμŠ΅λ‹ˆλ‹€`,
  "error.notFound": (name: string) => `${josa(name, "을λ₯Ό")} 찾을 수 μ—†μŠ΅λ‹ˆλ‹€`,
} as const;

// μ‚¬μš©
SD("validation.required")("이메일"); // "이메일은 ν•„μˆ˜μž…λ‹ˆλ‹€"
SD("validation.required")("이름"); // "이름은 ν•„μˆ˜μž…λ‹ˆλ‹€"

plural - λ³΅μˆ˜ν˜• 처리

plural() ν•¨μˆ˜λŠ” μˆ«μžμ— 따라 λ‹€λ₯Έ ν…μŠ€νŠΈλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€:
import { plural } from "sonamu/dict";

plural(0, { zero: "μ—†μŒ", one: "1개", other: "μ—¬λŸ¬ 개" }); // "μ—†μŒ"
plural(1, { zero: "μ—†μŒ", one: "1개", other: "μ—¬λŸ¬ 개" }); // "1개"
plural(5, { zero: "μ—†μŒ", one: "1개", other: "μ—¬λŸ¬ 개" }); // "μ—¬λŸ¬ 개"

// other에 ν•¨μˆ˜ μ‚¬μš©
plural(5, { other: (n) => `${n}개` }); // "5개"

// zeroλ‚˜ one이 μ—†μœΌλ©΄ other둜 폴백
plural(0, { other: "κΈ°λ³Έκ°’" }); // "κΈ°λ³Έκ°’"
plural(1, { other: "κΈ°λ³Έκ°’" }); // "κΈ°λ³Έκ°’"

μ˜΅μ…˜

μ˜΅μ…˜μ‘°κ±΄μ„€λͺ…
zeron === 00일 λ•Œ ν…μŠ€νŠΈ
onen === 11일 λ•Œ ν…μŠ€νŠΈ
otherκ·Έ μ™ΈκΈ°λ³Έ ν…μŠ€νŠΈ (ν•„μˆ˜)

λ”•μ…”λ„ˆλ¦¬μ—μ„œ μ‚¬μš©

// ko.ts
import { plural } from "sonamu/dict";

export default {
  "items.count": (count: number) =>
    plural(count, {
      zero: "ν•­λͺ©μ΄ μ—†μŠ΅λ‹ˆλ‹€",
      one: "1개 ν•­λͺ©",
      other: (n) => `${n}개 ν•­λͺ©`,
    }),

  "cart.items": (count: number) =>
    plural(count, {
      zero: "μž₯λ°”κ΅¬λ‹ˆκ°€ λΉ„μ–΄μžˆμŠ΅λ‹ˆλ‹€",
      other: (n) => `μž₯λ°”κ΅¬λ‹ˆμ— ${n}개 μƒν’ˆ`,
    }),
} as const;

createFormat - 숫자/λ‚ μ§œ 포맷

createFormat() ν•¨μˆ˜λŠ” locale에 λ§žλŠ” μˆ«μžμ™€ λ‚ μ§œ 포맷터λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€:
import { createFormat } from "sonamu/dict";

const format = createFormat("ko");

format.number(1234567); // "1,234,567"
format.date(new Date("2024-01-15")); // "2024. 1. 15."

const enFormat = createFormat("en");
enFormat.number(1234567); // "1,234,567"
enFormat.date(new Date("2024-01-15")); // "1/15/2024"

λ”•μ…”λ„ˆλ¦¬μ—μ„œ μ‚¬μš©

// ko.ts
import { createFormat } from "sonamu/dict";

const format = createFormat("ko");

export default {
  "price.display": (price: number) => `${format.number(price)}원`,
  "date.created": (date: Date) => `${format.date(date)} 등둝`,
  "validation.range": (field: string, min: number, max: number) =>
    `${field}은(λŠ”) ${format.number(min)}~${format.number(max)} 사이여야 ν•©λ‹ˆλ‹€`,
} as const;

μ—¬λŸ¬ 헬퍼 μ‘°ν•©

λ³΅μž‘ν•œ λ©”μ‹œμ§€λŠ” μ—¬λŸ¬ 헬퍼λ₯Ό μ‘°ν•©ν•΄μ„œ μž‘μ„±ν•©λ‹ˆλ‹€:
// ko.ts
import { createFormat, josa, plural } from "sonamu/dict";

const format = createFormat("ko");

export default {
  // josa + plural
  "search.results": (keyword: string, count: number) =>
    `'${keyword}'${josa(keyword, "으둜")} κ²€μƒ‰ν•œ κ²°κ³Ό ` +
    plural(count, {
      zero: "μ—†μŒ",
      other: (n) => `${format.number(n)}건`,
    }),

  // format + josa
  "order.total": (itemCount: number, total: number) =>
    `${itemCount}개 μƒν’ˆ, 총 ${format.number(total)}원`,

  // 볡합 λ©”μ‹œμ§€
  "dashboard.summary": (userName: string, taskCount: number, date: Date) =>
    `${userName}λ‹˜, ${format.date(date)} κΈ°μ€€ ` +
    plural(taskCount, {
      zero: "μ²˜λ¦¬ν•  μž‘μ—…μ΄ μ—†μŠ΅λ‹ˆλ‹€",
      one: "1개의 μž‘μ—…μ΄ λŒ€κΈ° μ€‘μž…λ‹ˆλ‹€",
      other: (n) => `${n}개의 μž‘μ—…μ΄ λŒ€κΈ° μ€‘μž…λ‹ˆλ‹€`,
    }),
} as const;

SD ν•¨μˆ˜ μ‚¬μš©λ²•

λ”•μ…”λ„ˆλ¦¬ μž‘μ„± 및 μ‚¬μš©

λ‹€κ΅­μ–΄ 컬럼

DB 컬럼 λ‹€κ΅­μ–΄ 지원