-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ [refactor]: Refactor decorators package, add autotranslate plugin …
…script
- Loading branch information
Showing
70 changed files
with
351 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
packages/core/src/decorators/types/DecoratorContext.type.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
import { $ } from "../types/namespace/Utility.ns"; | ||
import { getLocale } from "./model/Locale"; | ||
import translations from "./model/Translations"; | ||
import { getLocale } from "./model/locale"; | ||
import localizedMessages from "./model/messages"; | ||
|
||
function sprintf(str: string, ...args: any[]) { | ||
return str.replace(/{(\d+)}/g, function (match, number) { | ||
return typeof args[number] != "undefined" ? args[number] : match; | ||
}); | ||
} | ||
|
||
export type MessageFn<T extends any[] = []> = $.FuncFactory<T, string>; | ||
|
||
// Central method for getting translation handlers. | ||
export function t(key: string, ...args: any[]): string { | ||
const t = (key: string, ...args: any[]) => { | ||
const locale = getLocale(); | ||
const service = translations[locale]; | ||
const service = localizedMessages[locale]; | ||
return sprintf(service[key], ...args); | ||
} | ||
}; | ||
|
||
export default t; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { $ } from "../types/namespace/Utility.ns"; | ||
|
||
export type Locale = "hr" | "en"; | ||
|
||
export type LocaleDefault = "en"; | ||
|
||
export type MessageFn<T extends any[] = []> = $.FuncFactory<T, string>; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import t from "../message.factory"; | ||
|
||
// prettier-ignore | ||
const errorMessages = { | ||
Alpha: () => t("Alpha"), | ||
Alphanumeric: () => t("Alphanumeric"), | ||
ArrayContains: (o: any) => t("ArrayContains", JSON.stringify(o, null, 2)), | ||
ArrayEmpty: () => t("ArrayEmpty"), | ||
ArraySizeExact: (exact: number, actual: number) => t("ArraySizeExact", exact, actual), | ||
ArraySizeMax: (max: number, actual: number) => t("ArraySizeMax", max, actual), | ||
ArraySizeMin: (min: number, actual: number) => t("ArraySizeMin", min, actual), | ||
ArraySizeRange: (min: number, max: number, actual: number) => t("ArraySizeRange", min, max, actual), | ||
ArrayUnique: () => t("ArrayUnique"), | ||
Date: (format: string) => t("Date", format), | ||
Decimal: (actual: number) => t("Decimal", actual), | ||
Digits: (maxInteger: number, maxFraction: number) => t("Digits", maxInteger, maxFraction), | ||
Email: () => t("Email"), | ||
ExactLength: (exact: number) => t("ExactLength", exact), | ||
Falsy: () => t("Falsy"), | ||
FutureDate: (date: Date) => t("FutureDate", date?.toDateString()), | ||
IPAddress: () => t("IPAddress"), | ||
Integer: (actual: number) => t("Integer", actual), | ||
InvalidDigits: (maxInteger: number, maxFraction: number) => t("InvalidDigits", maxInteger, maxFraction), | ||
JSON: () => t("JSON"), | ||
Lowercase: () => t("Lowercase"), | ||
MaxLength: (max: number) => t("MaxLength", max), | ||
MinLength: (min: number) => t("MinLength", min), | ||
Negative: (actual: number) => t("Negative", actual), | ||
NonNegative: (actual: number) => t("NonNegative", actual), | ||
NonPositive: (actual: number) => t("NonPositive", actual), | ||
Numeric: () => t("Numeric"), | ||
PasswordLength: (length: number) => t("PasswordLength", length), | ||
PasswordLowercase: () => t("PasswordLowercase"), | ||
PasswordNumbers: () => t("PasswordNumbers"), | ||
PasswordSpecials: () => t("PasswordSpecials"), | ||
PasswordUppercase: () => t("PasswordUppercase"), | ||
PastDate: (date: Date) => t("PastDate", date?.toDateString()), | ||
Positive: (actual: number) => t("Positive", actual), | ||
RangeLength: (min: number, max: number) => t("RangeLength", min, max), | ||
Required: () => t('Required'), | ||
Time: (locale: string, hour12: boolean) => t("Time", locale, hour12 ? "12-hour" : "24:hour"), | ||
TodayDate: (date: Date) => t("TodayDate", date?.toDateString()), | ||
Truthy: () => t("Truthy"), | ||
Uppercase: () => t("Uppercase"), | ||
URL: () => t("URL"), | ||
ValueMax: (value: number, actual: number) => t("ValueMax", value, actual), | ||
ValueMin: (value: number, actual: number) => t("ValueMin", value, actual), | ||
ValueRange: (min: number, max: number, actual: number) => t("ValueRange", min, max, actual), | ||
XML: () => t("XML"), | ||
} as const; | ||
|
||
export default errorMessages; |
2 changes: 1 addition & 1 deletion
2
packages/core/src/messages/model/Locale.ts → packages/core/src/messages/model/locale.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export type Locale = "hr" | "en"; | ||
import { Locale } from "../message.types"; | ||
|
||
let locale: Locale = "en"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Locale } from "../message.types"; | ||
import * as MessageFormatEn from "../translations/en.json"; | ||
import * as MessageFormatHr from "../translations/hr.json"; | ||
|
||
export type LocalizedMessages = Record<Locale, Messages>; | ||
|
||
export type Messages = Record<string, string>; | ||
|
||
const localizedMessages: LocalizedMessages = { | ||
en: MessageFormatEn, | ||
hr: MessageFormatHr, | ||
}; | ||
|
||
export default localizedMessages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.