@14ch/svelte-ui 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,81 @@
1
+ export type Locale = 'en' | 'ja';
2
+ export declare const MESSAGES: {
3
+ readonly en: {
4
+ readonly datepicker: {
5
+ readonly prevMonth: "Previous month";
6
+ readonly nextMonth: "Next month";
7
+ readonly today: " today";
8
+ readonly selected: " selected";
9
+ };
10
+ readonly iconButton: {
11
+ readonly badgeNew: "New";
12
+ };
13
+ readonly imageUploader: {
14
+ readonly unsupportedFileFormat: "Unsupported file format";
15
+ readonly fileSizeExceeded: "File size must be {{maxSize}}MB or less";
16
+ readonly uploadImage: "Upload image";
17
+ readonly removeFile: "Remove image";
18
+ };
19
+ readonly fileUploader: {
20
+ readonly removeFile: "Remove file";
21
+ readonly uploadFile: "Upload file";
22
+ readonly placeholder: "Drag & drop files here<br />or click to select";
23
+ readonly maxFileSizeError: "File size must be {{maxSize}}MB or less";
24
+ };
25
+ readonly combobox: {
26
+ readonly optionsList: "Options list";
27
+ };
28
+ readonly input: {
29
+ readonly clear: "Clear";
30
+ };
31
+ readonly pagination: {
32
+ readonly prevPage: "Go to previous page";
33
+ readonly nextPage: "Go to next page";
34
+ readonly goToPage: "Go to page {{page}}";
35
+ readonly ellipsis: "Omitted pages";
36
+ };
37
+ };
38
+ readonly ja: {
39
+ readonly datepicker: {
40
+ readonly prevMonth: "前の月へ移動";
41
+ readonly nextMonth: "次の月へ移動";
42
+ readonly today: " 今日";
43
+ readonly selected: " 選択済み";
44
+ };
45
+ readonly iconButton: {
46
+ readonly badgeNew: "新しい";
47
+ };
48
+ readonly imageUploader: {
49
+ readonly unsupportedFileFormat: "サポートされていないファイル形式です";
50
+ readonly fileSizeExceeded: "ファイルサイズは{{maxSize}}MB以下にしてください";
51
+ readonly uploadImage: "画像をアップロード";
52
+ readonly removeFile: "画像を削除";
53
+ };
54
+ readonly fileUploader: {
55
+ readonly removeFile: "ファイルを削除";
56
+ readonly uploadFile: "ファイルをアップロード";
57
+ readonly placeholder: "ファイルをドラッグ&ドロップ<br />またはファイルを選択";
58
+ readonly maxFileSizeError: "ファイルサイズは{{maxSize}}MB以下にしてください";
59
+ };
60
+ readonly combobox: {
61
+ readonly optionsList: "オプション一覧";
62
+ };
63
+ readonly input: {
64
+ readonly clear: "クリア";
65
+ };
66
+ readonly pagination: {
67
+ readonly prevPage: "前のページへ移動";
68
+ readonly nextPage: "次のページへ移動";
69
+ readonly goToPage: "{{page}}ページ目へ移動";
70
+ readonly ellipsis: "省略されたページ";
71
+ };
72
+ };
73
+ };
74
+ export declare const getLocale: () => Locale;
75
+ type NestedKeyOf<T> = T extends object ? {
76
+ [K in keyof T]: K extends string ? T[K] extends object ? `${K}.${NestedKeyOf<T[K]>}` : K : never;
77
+ }[keyof T] : never;
78
+ export declare const t: (key: NestedKeyOf<typeof MESSAGES.en>, params?: Record<string, any>) => string;
79
+ export declare const debugLocale: () => Locale;
80
+ export declare const setLocale: (locale: Locale) => void;
81
+ export {};
@@ -0,0 +1,59 @@
1
+ import { en } from './locales/en';
2
+ import { ja } from './locales/ja';
3
+ export const MESSAGES = {
4
+ en,
5
+ ja
6
+ };
7
+ // ブラウザの言語設定を取得
8
+ export const getLocale = () => {
9
+ if (typeof navigator !== 'undefined') {
10
+ // navigator.languages を使用して言語の優先順位を確認
11
+ const languages = navigator.languages || [navigator.language];
12
+ // 最初の言語(最優先言語)をチェック
13
+ const primaryLanguage = languages[0];
14
+ if (primaryLanguage.startsWith('ja')) {
15
+ return 'ja';
16
+ }
17
+ }
18
+ return 'en';
19
+ };
20
+ // パラメータ置換のヘルパー関数
21
+ const replaceParams = (message, params) => {
22
+ if (!params)
23
+ return message;
24
+ return message.replace(/\{\{(\w+)\}\}/g, (match, key) => {
25
+ return params[key] !== undefined ? String(params[key]) : match;
26
+ });
27
+ };
28
+ // 標準的なi18n関数
29
+ export const t = (key, params) => {
30
+ const locale = getLocaleWithManual();
31
+ const message = key.split('.').reduce((obj, k) => obj?.[k], MESSAGES[locale]);
32
+ if (typeof message !== 'string') {
33
+ console.warn(`Translation key "${key}" not found for locale "${locale}"`);
34
+ return key;
35
+ }
36
+ return replaceParams(message, params);
37
+ };
38
+ // デバッグ用: 現在の言語設定を確認
39
+ export const debugLocale = () => {
40
+ if (typeof navigator !== 'undefined') {
41
+ console.log('navigator.language:', navigator.language);
42
+ console.log('navigator.languages:', navigator.languages);
43
+ console.log('detected locale:', getLocale());
44
+ }
45
+ return getLocale();
46
+ };
47
+ // テスト用: 手動で言語を切り替え
48
+ let manualLocale = null;
49
+ export const setLocale = (locale) => {
50
+ manualLocale = locale;
51
+ console.log(`🔧 Manual locale set to: ${locale}`);
52
+ };
53
+ // 手動設定を優先するgetLocale
54
+ const getLocaleWithManual = () => {
55
+ if (manualLocale) {
56
+ return manualLocale;
57
+ }
58
+ return getLocale();
59
+ };
@@ -0,0 +1,35 @@
1
+ export declare const en: {
2
+ readonly datepicker: {
3
+ readonly prevMonth: "Previous month";
4
+ readonly nextMonth: "Next month";
5
+ readonly today: " today";
6
+ readonly selected: " selected";
7
+ };
8
+ readonly iconButton: {
9
+ readonly badgeNew: "New";
10
+ };
11
+ readonly imageUploader: {
12
+ readonly unsupportedFileFormat: "Unsupported file format";
13
+ readonly fileSizeExceeded: "File size must be {{maxSize}}MB or less";
14
+ readonly uploadImage: "Upload image";
15
+ readonly removeFile: "Remove image";
16
+ };
17
+ readonly fileUploader: {
18
+ readonly removeFile: "Remove file";
19
+ readonly uploadFile: "Upload file";
20
+ readonly placeholder: "Drag & drop files here<br />or click to select";
21
+ readonly maxFileSizeError: "File size must be {{maxSize}}MB or less";
22
+ };
23
+ readonly combobox: {
24
+ readonly optionsList: "Options list";
25
+ };
26
+ readonly input: {
27
+ readonly clear: "Clear";
28
+ };
29
+ readonly pagination: {
30
+ readonly prevPage: "Go to previous page";
31
+ readonly nextPage: "Go to next page";
32
+ readonly goToPage: "Go to page {{page}}";
33
+ readonly ellipsis: "Omitted pages";
34
+ };
35
+ };
@@ -0,0 +1,35 @@
1
+ export const en = {
2
+ datepicker: {
3
+ prevMonth: 'Previous month',
4
+ nextMonth: 'Next month',
5
+ today: ' today',
6
+ selected: ' selected'
7
+ },
8
+ iconButton: {
9
+ badgeNew: 'New'
10
+ },
11
+ imageUploader: {
12
+ unsupportedFileFormat: 'Unsupported file format',
13
+ fileSizeExceeded: 'File size must be {{maxSize}}MB or less',
14
+ uploadImage: 'Upload image',
15
+ removeFile: 'Remove image'
16
+ },
17
+ fileUploader: {
18
+ removeFile: 'Remove file',
19
+ uploadFile: 'Upload file',
20
+ placeholder: 'Drag & drop files here<br />or click to select',
21
+ maxFileSizeError: 'File size must be {{maxSize}}MB or less'
22
+ },
23
+ combobox: {
24
+ optionsList: 'Options list'
25
+ },
26
+ input: {
27
+ clear: 'Clear'
28
+ },
29
+ pagination: {
30
+ prevPage: 'Go to previous page',
31
+ nextPage: 'Go to next page',
32
+ goToPage: 'Go to page {{page}}',
33
+ ellipsis: 'Omitted pages'
34
+ }
35
+ };
@@ -0,0 +1,35 @@
1
+ export declare const ja: {
2
+ readonly datepicker: {
3
+ readonly prevMonth: "前の月へ移動";
4
+ readonly nextMonth: "次の月へ移動";
5
+ readonly today: " 今日";
6
+ readonly selected: " 選択済み";
7
+ };
8
+ readonly iconButton: {
9
+ readonly badgeNew: "新しい";
10
+ };
11
+ readonly imageUploader: {
12
+ readonly unsupportedFileFormat: "サポートされていないファイル形式です";
13
+ readonly fileSizeExceeded: "ファイルサイズは{{maxSize}}MB以下にしてください";
14
+ readonly uploadImage: "画像をアップロード";
15
+ readonly removeFile: "画像を削除";
16
+ };
17
+ readonly fileUploader: {
18
+ readonly removeFile: "ファイルを削除";
19
+ readonly uploadFile: "ファイルをアップロード";
20
+ readonly placeholder: "ファイルをドラッグ&ドロップ<br />またはファイルを選択";
21
+ readonly maxFileSizeError: "ファイルサイズは{{maxSize}}MB以下にしてください";
22
+ };
23
+ readonly combobox: {
24
+ readonly optionsList: "オプション一覧";
25
+ };
26
+ readonly input: {
27
+ readonly clear: "クリア";
28
+ };
29
+ readonly pagination: {
30
+ readonly prevPage: "前のページへ移動";
31
+ readonly nextPage: "次のページへ移動";
32
+ readonly goToPage: "{{page}}ページ目へ移動";
33
+ readonly ellipsis: "省略されたページ";
34
+ };
35
+ };
@@ -0,0 +1,35 @@
1
+ export const ja = {
2
+ datepicker: {
3
+ prevMonth: '前の月へ移動',
4
+ nextMonth: '次の月へ移動',
5
+ today: ' 今日',
6
+ selected: ' 選択済み'
7
+ },
8
+ iconButton: {
9
+ badgeNew: '新しい'
10
+ },
11
+ imageUploader: {
12
+ unsupportedFileFormat: 'サポートされていないファイル形式です',
13
+ fileSizeExceeded: 'ファイルサイズは{{maxSize}}MB以下にしてください',
14
+ uploadImage: '画像をアップロード',
15
+ removeFile: '画像を削除'
16
+ },
17
+ fileUploader: {
18
+ removeFile: 'ファイルを削除',
19
+ uploadFile: 'ファイルをアップロード',
20
+ placeholder: 'ファイルをドラッグ&ドロップ<br />またはファイルを選択',
21
+ maxFileSizeError: 'ファイルサイズは{{maxSize}}MB以下にしてください'
22
+ },
23
+ combobox: {
24
+ optionsList: 'オプション一覧'
25
+ },
26
+ input: {
27
+ clear: 'クリア'
28
+ },
29
+ pagination: {
30
+ prevPage: '前のページへ移動',
31
+ nextPage: '次のページへ移動',
32
+ goToPage: '{{page}}ページ目へ移動',
33
+ ellipsis: '省略されたページ'
34
+ }
35
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@14ch/svelte-ui",
3
3
  "description": "Modern Svelte UI components library with TypeScript support",
4
4
  "private": false,
5
- "version": "0.0.1",
5
+ "version": "0.0.2",
6
6
  "type": "module",
7
7
  "keywords": [
8
8
  "svelte",
@@ -36,6 +36,7 @@
36
36
  "dist/types/",
37
37
  "dist/utils/",
38
38
  "dist/assets/",
39
+ "dist/i18n/",
39
40
  "dist/index.js",
40
41
  "dist/index.d.ts"
41
42
  ],