Skip to content

Commit

Permalink
include LanguageTag from versioned-interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jldec committed May 9, 2024
1 parent 7b78b8a commit c7c332a
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions inlang/source-code/sdk/src/v2/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
import { LanguageTag as Locale } from "@inlang/language-tag"
import { Type, type Static } from "@sinclair/typebox"

/**
* Follows the IETF BCP 47 language tag schema.
*
* @see https://www.ietf.org/rfc/bcp/bcp47.txt
* @see https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry
*/
export type LanguageTag = Static<typeof LanguageTag>
/**
* Follows the IETF BCP 47 language tag schema with modifications.
* @see REAMDE.md file for more information on the validation.
*/

export const pattern =
"^((?<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?<language>([A-Za-z]{2,3}(-(?<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?))(-(?<script>[A-Za-z]{4}))?(-(?<region>[A-Za-z]{2}|[0-9]{3}))?(-(?<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*))$"

export const LanguageTag = Type.String({
pattern: pattern,
description: "The language tag must be a valid IETF BCP 47 language tag.",
examples: ["en", "de", "en-US", "zh-Hans", "es-419"],
})

export type Literal = Static<typeof Literal>
export const Literal = Type.Object({
type: Type.Literal("literal"),
Expand Down Expand Up @@ -105,7 +125,7 @@ export const Declaration = Type.Union([InputDeclaration])

export type Message = Static<typeof Message>
export const Message = Type.Object({
locale: Locale,
locale: LanguageTag,
declarations: Type.Array(Declaration),
/**
* The order in which the selectors are placed determines the precedence of patterns.
Expand Down

0 comments on commit c7c332a

Please sign in to comment.