mirror of
https://github.com/cupcakearmy/svelte-i18n.git
synced 2024-11-16 09:59:58 +01:00
parent
107eec0e89
commit
dadeaa2e7f
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
node_modules
|
||||
*.log
|
||||
dist/
|
||||
coverage/
|
||||
coverage/
|
||||
types/
|
16
package.json
16
package.json
@ -1,8 +1,9 @@
|
||||
{
|
||||
"name": "svelte-i18n",
|
||||
"version": "2.2.4",
|
||||
"main": "dist/i18n.cjs.js",
|
||||
"module": "dist/i18n.esm.js",
|
||||
"main": "dist/runtime.cjs.js",
|
||||
"module": "dist/runtime.esm.js",
|
||||
"types": "types/runtime/index.d.ts",
|
||||
"bin": {
|
||||
"svelte-i18n": "dist/cli.js"
|
||||
},
|
||||
@ -21,21 +22,26 @@
|
||||
"node": ">= 11.15.0"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rm -rf dist/ types/",
|
||||
"build": "rollup -c",
|
||||
"build:types": "tsc -p src/runtime --emitDeclarationOnly",
|
||||
"dev": "rollup -c -w",
|
||||
"pretest": "npm run build",
|
||||
"test": "jest",
|
||||
"test:ci": "jest --silent",
|
||||
"test:watch": "jest --verbose --watchAll",
|
||||
"lint": "eslint \"src/**/*.ts\"",
|
||||
"format": "prettier --loglevel silent --write \"src/**/*.ts\" && eslint --fix \"src/**/*.ts\"",
|
||||
"prerelease": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1 && git add CHANGELOG.md",
|
||||
"release": " git add package.json && git commit -m \"chore(release): v$npm_package_version :tada:\"",
|
||||
"pretest": "npm run build",
|
||||
"prebuild": "yarn clean",
|
||||
"postbuild": "yarn build:types",
|
||||
"prerelease": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1 && git add CHANGELOG.md",
|
||||
"postrelease": "git tag -a v$npm_package_version -m 'Release v$npm_package_version'",
|
||||
"prepublishOnly": "run-s test:ci build release"
|
||||
},
|
||||
"files": [
|
||||
"dist/"
|
||||
"dist/",
|
||||
"types/"
|
||||
],
|
||||
"jest": {
|
||||
"collectCoverage": true,
|
||||
|
@ -9,7 +9,7 @@ const PROD = !process.env.ROLLUP_WATCH
|
||||
|
||||
export default [
|
||||
{
|
||||
input: 'src/client/index.ts',
|
||||
input: 'src/runtime/index.ts',
|
||||
external: [
|
||||
...Object.keys(pkg.dependencies),
|
||||
...Object.keys(pkg.peerDependencies),
|
||||
|
@ -1,66 +0,0 @@
|
||||
import { Formats } from 'intl-messageformat'
|
||||
|
||||
export interface DeepDictionary {
|
||||
[key: string]: DeepDictionary | string | string[]
|
||||
}
|
||||
export type LocaleDictionary = Record<string, string>
|
||||
export type Dictionary = Record<string, LocaleDictionary>
|
||||
|
||||
export interface MessageObject {
|
||||
id?: string
|
||||
locale?: string
|
||||
format?: string
|
||||
default?: string
|
||||
values?: Record<string, string | number | Date>
|
||||
}
|
||||
|
||||
interface FormatterFn {
|
||||
(id: string | MessageObject, options?: MessageObject): string
|
||||
}
|
||||
|
||||
type IntlFormatterOptions<T> = T & {
|
||||
format?: string
|
||||
locale?: string
|
||||
}
|
||||
|
||||
export interface MemoizedIntlFormatter<T, U> {
|
||||
(options?: IntlFormatterOptions<U>): T
|
||||
}
|
||||
|
||||
export interface Formatter extends FormatterFn {
|
||||
time: (
|
||||
d: Date | number,
|
||||
options?: IntlFormatterOptions<Intl.DateTimeFormatOptions>
|
||||
) => string
|
||||
date: (
|
||||
d: Date | number,
|
||||
options?: IntlFormatterOptions<Intl.DateTimeFormatOptions>
|
||||
) => string
|
||||
number: (
|
||||
d: number,
|
||||
options?: IntlFormatterOptions<Intl.NumberFormatOptions>
|
||||
) => string
|
||||
capital: FormatterFn
|
||||
title: FormatterFn
|
||||
upper: FormatterFn
|
||||
lower: FormatterFn
|
||||
}
|
||||
|
||||
export interface MessagesLoader {
|
||||
(): Promise<any>
|
||||
}
|
||||
|
||||
export interface GetClientLocaleOptions {
|
||||
navigator?: boolean
|
||||
hash?: string
|
||||
search?: string
|
||||
pathname?: RegExp
|
||||
hostname?: RegExp
|
||||
}
|
||||
|
||||
export interface ConfigureOptions {
|
||||
fallbackLocale: string
|
||||
initialLocale?: string | GetClientLocaleOptions
|
||||
formats?: Partial<Formats>
|
||||
loadingDelay?: number
|
||||
}
|
8
src/runtime/tsconfig.json
Normal file
8
src/runtime/tsconfig.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"declarationDir": "../../types/runtime"
|
||||
},
|
||||
"include": ["."]
|
||||
}
|
@ -5,8 +5,8 @@ import {
|
||||
getOptions,
|
||||
defaultOptions,
|
||||
defaultFormats,
|
||||
} from '../../src/client/configs'
|
||||
import { $locale } from '../../src/client/stores/locale'
|
||||
} from '../../src/runtime/configs'
|
||||
import { $locale } from '../../src/runtime/stores/locale'
|
||||
|
||||
beforeEach(() => {
|
||||
init(defaultOptions)
|
@ -4,7 +4,7 @@ import {
|
||||
getTimeFormatter,
|
||||
getMessageFormatter,
|
||||
init
|
||||
} from '../../../src/client'
|
||||
} from '../../../src/runtime'
|
||||
|
||||
beforeEach(() => {
|
||||
init({ fallbackLocale: undefined })
|
@ -5,10 +5,10 @@ import {
|
||||
flush,
|
||||
registerLocaleLoader,
|
||||
resetQueues,
|
||||
} from '../../../src/client/includes/loaderQueue'
|
||||
import { getMessageFromDictionary } from '../../../src/client/stores/dictionary'
|
||||
import { $isLoading } from '../../../src/client/stores/loading'
|
||||
import { getOptions } from '../../../src/client/configs'
|
||||
} from '../../../src/runtime/includes/loaderQueue'
|
||||
import { getMessageFromDictionary } from '../../../src/runtime/stores/dictionary'
|
||||
import { $isLoading } from '../../../src/runtime/stores/loading'
|
||||
import { getOptions } from '../../../src/runtime/configs'
|
||||
|
||||
beforeEach(() => {
|
||||
resetQueues()
|
@ -1,5 +1,5 @@
|
||||
import { lookup, lookupCache } from '../../../src/client/includes/lookup'
|
||||
import { $dictionary, addMessages } from '../../../src/client/stores/dictionary'
|
||||
import { lookup, lookupCache } from '../../../src/runtime/includes/lookup'
|
||||
import { $dictionary, addMessages } from '../../../src/runtime/stores/dictionary'
|
||||
|
||||
beforeEach(() => {
|
||||
$dictionary.set({})
|
@ -5,7 +5,7 @@ import {
|
||||
upper,
|
||||
lower,
|
||||
flatObj,
|
||||
} from '../../../src/client/includes/utils'
|
||||
} from '../../../src/runtime/includes/utils'
|
||||
|
||||
describe('getting client locale', () => {
|
||||
beforeEach(() => {
|
@ -1,11 +1,11 @@
|
||||
import { defineMessages, waitLocale, register, init } from '../../src/client'
|
||||
import { $locale } from '../../src/client/stores/locale'
|
||||
import { hasLocaleQueue } from '../../src/client/includes/loaderQueue'
|
||||
import { defineMessages, waitLocale, register, init } from '../../src/runtime'
|
||||
import { $locale } from '../../src/runtime/stores/locale'
|
||||
import { hasLocaleQueue } from '../../src/runtime/includes/loaderQueue'
|
||||
import {
|
||||
getLocaleDictionary,
|
||||
$dictionary,
|
||||
} from '../../src/client/stores/dictionary'
|
||||
import { $format } from '../../src/client/stores/format'
|
||||
} from '../../src/runtime/stores/dictionary'
|
||||
import { $format } from '../../src/runtime/stores/format'
|
||||
|
||||
test('defineMessages returns the identity of its first argument', () => {
|
||||
const obj = {}
|
@ -9,7 +9,7 @@ import {
|
||||
$dictionary,
|
||||
$locales,
|
||||
getLocaleDictionary,
|
||||
} from '../../../src/client/stores/dictionary'
|
||||
} from '../../../src/runtime/stores/dictionary'
|
||||
|
||||
beforeEach(() => {
|
||||
$dictionary.set({})
|
@ -1,8 +1,8 @@
|
||||
import { Formatter } from '../../../src/client/types/index'
|
||||
import { $format } from '../../../src/client/stores/format'
|
||||
import { init } from '../../../src/client/configs'
|
||||
import { addMessages } from '../../../src/client/stores/dictionary'
|
||||
import { $locale } from '../../../src/client/stores/locale'
|
||||
import { Formatter } from '../../../src/runtime/types/index'
|
||||
import { $format } from '../../../src/runtime/stores/format'
|
||||
import { init } from '../../../src/runtime/configs'
|
||||
import { addMessages } from '../../../src/runtime/stores/dictionary'
|
||||
import { $locale } from '../../../src/runtime/stores/locale'
|
||||
|
||||
let format: Formatter
|
||||
$format.subscribe(f => (format = f))
|
@ -1,6 +1,6 @@
|
||||
import { get } from 'svelte/store'
|
||||
|
||||
import { lookup } from '../../../src/client/includes/lookup'
|
||||
import { lookup } from '../../../src/runtime/includes/lookup'
|
||||
import {
|
||||
isFallbackLocaleOf,
|
||||
getFallbackOf,
|
||||
@ -8,10 +8,10 @@ import {
|
||||
getCurrentLocale,
|
||||
$locale,
|
||||
isRelatedLocale,
|
||||
} from '../../../src/client/stores/locale'
|
||||
import { getOptions, init } from '../../../src/client/configs'
|
||||
import { register } from '../../../src/client'
|
||||
import { hasLocaleQueue } from '../../../src/client/includes/loaderQueue'
|
||||
} from '../../../src/runtime/stores/locale'
|
||||
import { getOptions, init } from '../../../src/runtime/configs'
|
||||
import { register } from '../../../src/runtime'
|
||||
import { hasLocaleQueue } from '../../../src/runtime/includes/loaderQueue'
|
||||
|
||||
beforeEach(() => {
|
||||
init({ fallbackLocale: undefined })
|
@ -11,6 +11,5 @@
|
||||
"lib": ["es2018", "dom", "esnext"],
|
||||
"outDir": "dist",
|
||||
"types": ["svelte", "jest"]
|
||||
},
|
||||
"exclude": ["node_modules/**/*", "dist"]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user