@moneko/solid 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/env.d.ts +51 -0
  2. package/package.json +1 -1
package/env.d.ts CHANGED
@@ -154,6 +154,57 @@ declare module '@app/coverage' {
154
154
 
155
155
  export default coverage;
156
156
  }
157
+ declare module '@app/locales' {
158
+ import type { SetStoreFunction } from 'solid-js/store';
159
+ export type LocaleConfig = {
160
+ /** 语言名称 (未设置时使用文件名)*/
161
+ language?: string;
162
+ /** 描述 */
163
+ title: string;
164
+ /** Icon */
165
+ icon?: string;
166
+ /** 翻译字典 */
167
+ translation: Record<string, string>;
168
+ };
169
+ type LocaleConfigMap = Record<string, Locale>;
170
+ export type InterpolationType<T extends string> = {
171
+ [K in T]?: string | number | symbol | boolean;
172
+ };
173
+ export interface Locale extends LocaleConfig {
174
+ language: string;
175
+ }
176
+ /** 获取当前项目的语言列表 */
177
+ export const locales: Pick<Locale, 'language' | 'icon' | 'title'>[] = [];
178
+ export const resources: Partial<LocaleConfigMap> = {};
179
+ /**
180
+ * 插值字符串; 替换字符串中的占位符 `${}` 为对应的值
181
+ * @param {string} str 包含占位符的字符串
182
+ * @param {Argument} values 用于替换占位符的值,按照占位符出现的顺序排列
183
+ * @returns {string} 替换后的字符串
184
+ */
185
+ export function interpolateString<T extends string>(
186
+ str: string,
187
+ values: InterpolationType<T>,
188
+ ): string;
189
+ /** 设置语言
190
+ * @param {string} localeName 语言名称
191
+ * @returns {void}
192
+ * @example
193
+ * ```js
194
+ * setLang('zh_CN');
195
+ * ```
196
+ */
197
+ export function setLang(localeName: string): void;
198
+ /** 使用的语言 */
199
+ export const lang: Omit<Locale, 'translation'>;
200
+ /** 映射 */
201
+ export const t: Record<string, string>;
202
+ /** 设置 */
203
+ export const setLocalizable: SetStoreFunction<{
204
+ lang: Omit<Locale, 'translation'>;
205
+ t: Record<string, string>;
206
+ }>;
207
+ }
157
208
  declare module '@app/fallback' {
158
209
  import { JSX } from 'solid-js';
159
210
  const Fallback: null | (() => JSX.Element);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moneko/solid",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Solid js",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {