wuchale 0.3.0 → 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
  ```
@@ -279,9 +284,10 @@ script rule below.
279
284
  ### Script
280
285
 
281
286
  This includes all JS/TS code that is:
282
- - Inside `<script>` tags
283
- - Inside dynamic expressions inside the markup or attributes, anything in curly braces like `{call('this guy')}`
284
- - In `*.svelte.[js|ts]` files.
287
+
288
+ - Inside `<script>` tags
289
+ - Inside dynamic expressions inside the markup or attributes, anything in curly braces like `{call('this guy')}`
290
+ - In `*.svelte.[js|ts]` files.
285
291
 
286
292
  The rule for this is that all strings and template strings that start with
287
293
  capital letters are extracted. Additionally, if they are used inside the
@@ -347,7 +353,6 @@ export const defaultOptions = {
347
353
  sourceLocale: 'en',
348
354
  otherLocales: ['am'],
349
355
  localesDir: './locales',
350
- importFrom: 'wuchale/runtime.svelte',
351
356
  heuristic: defaultHeuristic,
352
357
  geminiAPIKey: 'env',
353
358
  }
@@ -363,6 +368,27 @@ it here. The function should receive the following arguments:
363
368
 
364
369
  And it should return boolean to indicate whether to extract it.
365
370
 
371
+ ## Files management
372
+
373
+ `wuchale` generates two files for each locale.
374
+
375
+ ### `.po` file
376
+
377
+ This is a `gettext` file that is used to exchange the text fragments with translators. The workflow is:
378
+
379
+ - You give them the file with empty places for the translated fragments
380
+ - They fill it with the translation, preserving the placeholders, but they can change the orders as the language requires.
381
+ - You get the file back and make it part of your codebase.
382
+
383
+ **Note**: You should commit these files, they are where the translated
384
+ fragments are stored and are the source of truth for the translations.
385
+
386
+ ### Compiled `.json` file
387
+
388
+ This is the compiled version of the `.po` file. It is generated at the startup
389
+ of the dev server and at build time. As it has to be generated every time, you
390
+ should consider it as a temp file and therefore you should **not** commit it.
391
+
366
392
  ## 🧹 Cleaning
367
393
 
368
394
  Unused keys are marked as obsolete during a production build. Obsoletes are
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import wuchale from "./preprocess/index.js"
1
+ import plugin from "./preprocess/index.js"
2
2
 
3
- export default wuchale
3
+ export const wuchale = plugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wuchale",
3
- "version": "0.3.0",
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