wuchale 0.3.1 → 0.3.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.
package/README.md CHANGED
@@ -97,8 +97,8 @@ export default {
97
97
 
98
98
  ```
99
99
 
100
- Create `/locales/` if it doesn't exist, and then set it up in your main
101
- component. Assuming `/src/App.svelte`:
100
+ Create `/src/locales/` (relative to the projects root) if it doesn't exist, and
101
+ then set it up in your main component. Assuming `/src/App.svelte`:
102
102
 
103
103
  ```svelte
104
104
  <script>
@@ -107,9 +107,14 @@ component. Assuming `/src/App.svelte`:
107
107
  let locale = $state('en')
108
108
 
109
109
  $effect.pre(() => {
110
- import(`../locales/${locale}.json`).then(mod => {
110
+ // IMPORTANT! The path should be relative to the current file (vite restriction).
111
+ // for the default sveltekit template for example, it's `../locales/${locale}.json`
112
+ // because the default main component is located at /src/routes/+page.svelte
113
+ import(`./locales/${locale}.json`).then(mod => {
111
114
  setTranslations(mod.default)
112
115
  })
116
+ // but this only applies if you want to do lazy loading.
117
+ // Otherwise you can do an absolute import
113
118
  })
114
119
  </script>
115
120
  ```
@@ -348,7 +353,6 @@ export const defaultOptions = {
348
353
  sourceLocale: 'en',
349
354
  otherLocales: ['am'],
350
355
  localesDir: './locales',
351
- importFrom: 'wuchale/runtime.svelte',
352
356
  heuristic: defaultHeuristic,
353
357
  geminiAPIKey: 'env',
354
358
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wuchale",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "i18n for svelte without turning your codebase upside down",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -9,8 +9,7 @@ import { normalize, relative } from "node:path"
9
9
  export const defaultOptions = {
10
10
  sourceLocale: 'en',
11
11
  otherLocales: ['am'],
12
- localesDir: './locales',
13
- importFrom: 'wuchale/runtime.svelte',
12
+ localesDir: './src/locales',
14
13
  heuristic: defaultHeuristic,
15
14
  geminiAPIKey: 'env',
16
15
  }
@@ -121,7 +120,7 @@ export default async function wuchale(options = defaultOptions) {
121
120
  * @param {string} filename
122
121
  */
123
122
  async function preprocess(content, ast, filename) {
124
- const prep = new Preprocess(indexTracker, options.heuristic, options.importFrom)
123
+ const prep = new Preprocess(indexTracker, options.heuristic)
125
124
  const txts = prep.process(content, ast)
126
125
  if (!txts.length) {
127
126
  return {}
@@ -72,7 +72,7 @@ export default class Preprocess {
72
72
  * @param {HeuristicFunc} heuristic
73
73
  * @param {string} importFrom
74
74
  */
75
- constructor(index, heuristic = defaultHeuristic, importFrom) {
75
+ constructor(index, heuristic = defaultHeuristic, importFrom = 'wuchale/runtime.svelte') {
76
76
  this.index = index
77
77
  this.importFrom = importFrom
78
78
  this.heuristic = heuristic