@vocab/phrase 2.0.2 → 2.1.1

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
@@ -13,6 +13,17 @@ Vocab helps you ship multiple languages without compromising the reliability of
13
13
  - **Strongly typed with TypeScript**\
14
14
  When using translations TypeScript will ensure code only accesses valid translations and translations are passed all required dynamic values.
15
15
 
16
+ ## Table of contents
17
+
18
+ - [Getting started](#getting-started)
19
+ - [Step 1: Install Dependencies](#step-1-install-dependencies)
20
+ - [Step 2: Configure Vocab](#step-2-configure-vocab)
21
+ - [Step 3: Set the language using the React Provider](#step-3-set-the-language-using-the-react-provider)
22
+ - [Step 4: Create translations](#step-4-create-translations)
23
+ - [Step 5: Compile and consume translations](#step-5-compile-and-consume-translations)
24
+ - [Step 6: [Optional] Set up plugin](#step-6-optional-set-up-plugin)
25
+ - [Step 7: [Optional] Optimize for fast page loading](#step-7-optional-optimize-for-fast-page-loading)
26
+
16
27
  ## Getting started
17
28
 
18
29
  ### Step 1: Install Dependencies
@@ -159,7 +170,9 @@ function MyComponent({ children }) {
159
170
  }
160
171
  ```
161
172
 
162
- ### Step 6: [Optional] Set up Webpack plugin
173
+ ### Step 6: [Optional] Set up plugin
174
+
175
+ #### Webpack Plugin
163
176
 
164
177
  With the default setup, every language is loaded into your web application all the time, potentially leading to a large bundle size.
165
178
  Ideally you will want to switch out the Node.js/default runtime for the web runtime, which only loads the active language.
@@ -181,6 +194,85 @@ module.exports = {
181
194
  };
182
195
  ```
183
196
 
197
+ #### Vite Plugin _(this plugin is experimental)_
198
+
199
+ > [!NOTE]
200
+ > This plugin is still experimental and may not work in all cases. If you encounter any issues, please open an issue on the Vocab GitHub repository.
201
+
202
+ Vocab also provides a Vite plugin to handle the same functionality as the Webpack plugin.
203
+
204
+ ```shell
205
+ npm i --save-dev @vocab/vite
206
+ ```
207
+
208
+ default usage
209
+
210
+ ```js
211
+ // vite.config.js
212
+ import { defineConfig } from 'vite';
213
+ import { vocabPluginVite } from '@vocab/vite';
214
+ import vocabConfig from './vocab.config.cjs';
215
+
216
+ export default defineConfig({
217
+ plugins: [
218
+ vocabPluginVite({
219
+ vocabConfig
220
+ })
221
+ ]
222
+ });
223
+ ```
224
+
225
+ #### createVocabChunks
226
+
227
+ If you want to combine all language files into a single chunk, you can use the `createVocabChunks` function.
228
+ Simply use the function in your `manualChunks` configuration.
229
+
230
+ ```js
231
+ // vite.config.js
232
+ import { defineConfig } from 'vite';
233
+ import { vocabPluginVite } from '@vocab/vite';
234
+ import { createVocabChunks } from '@vocab/vite/create-vocab-chunks';
235
+ import vocabConfig from './vocab.config.cjs';
236
+
237
+ export default defineConfig({
238
+ plugins: [
239
+ vocabPluginVite({
240
+ vocabConfig
241
+ })
242
+ ],
243
+ build: {
244
+ rollupOptions: {
245
+ output: {
246
+ manualChunks: (id, ctx) => {
247
+ // handle your own manual chunks before or after the vocab chunks.
248
+ const languageChunkName = createVocabChunks(
249
+ id,
250
+ ctx
251
+ );
252
+ if (languageChunkName) {
253
+ // vocab has found a language chunk. Either return it or handle it in your own way.
254
+ return languageChunkName;
255
+ }
256
+ }
257
+ }
258
+ }
259
+ }
260
+ });
261
+ ```
262
+
263
+ #### VocabPluginOptions
264
+
265
+ ```ts
266
+ type VocabPluginOptions = {
267
+ /**
268
+ * The Vocab configuration file.
269
+ * The type can be found in the `@vocab/core/types`.
270
+ * This value is required
271
+ */
272
+ vocabConfig: UserConfig;
273
+ };
274
+ ```
275
+
184
276
  ### Step 7: [Optional] Optimize for fast page loading
185
277
 
186
278
  Using the above method without optimizing what chunks webpack uses you may find the page needing to do an extra round trip to load languages on a page.
@@ -207,7 +299,7 @@ extractor.addChunk(chunkName);
207
299
 
208
300
  Translation messages can sometimes contain dynamic values, such as dates/times, links, usernames, etc.
209
301
  These values often exist somewhere in the middle of a message, and could change location depending on the translation.
210
- To support this, Vocab uses [Format.js's `intl-messageformat` library], which enables you to use [ICU Message syntax](https://formatjs.io/docs/core-concepts/icu-syntax/) in your messages.
302
+ To support this, Vocab uses [Format.js's `intl-messageformat` library], which enables you to use [ICU Message syntax](https://formatjs.github.io/docs/core-concepts/icu-syntax/) in your messages.
211
303
 
212
304
  In the below example we are defining two messages: one that accepts a single parameter, and one that accepts a component.
213
305
 
@@ -231,7 +323,7 @@ t('my key with component', {
231
323
  });
232
324
  ```
233
325
 
234
- [Format.js's `intl-messageformat` library]: https://formatjs.io/docs/intl-messageformat/
326
+ [Format.js's `intl-messageformat` library]: https://formatjs.github.io/docs/intl-messageformat/
235
327
 
236
328
  ## Overriding the Locale
237
329
 
@@ -254,7 +346,7 @@ This can be useful in certain situations:
254
346
  For example: `th-u-ca-gregory`.
255
347
  See the [MDN Intl docs] for more information on BCP 47 extension sequences.
256
348
 
257
- [`intl-messageformat`]: https://formatjs.io/docs/intl-messageformat/
349
+ [`intl-messageformat`]: https://formatjs.github.io/docs/intl-messageformat/
258
350
  [IETF language tag]: https://en.wikipedia.org/wiki/IETF_language_tag
259
351
  [mdn intl docs]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#locales_argument
260
352
 
@@ -311,8 +403,8 @@ const Currency = ({ value, currency }) => {
311
403
  };
312
404
  ```
313
405
 
314
- [numbers]: https://formatjs.io/docs/core-concepts/icu-syntax/#number-type
315
- [dates, and times]: https://formatjs.io/docs/core-concepts/icu-syntax/#supported-datetime-skeleton
406
+ [numbers]: https://formatjs.github.io/docs/core-concepts/icu-syntax/#number-type
407
+ [dates, and times]: https://formatjs.github.io/docs/core-concepts/icu-syntax/#supported-datetime-skeleton
316
408
 
317
409
  ## Configuration
318
410
 
@@ -452,7 +544,7 @@ const App = () => (
452
544
  );
453
545
  ```
454
546
 
455
- [icu message syntax]: https://formatjs.io/docs/intl-messageformat/#message-syntax
547
+ [icu message syntax]: https://formatjs.github.io/docs/intl-messageformat/#message-syntax
456
548
  [diacritics]: https://en.wikipedia.org/wiki/Diacritic
457
549
 
458
550
  ## Pseudo-localization
@@ -629,6 +721,17 @@ referenced in the upload. These keys can be deleted from Phrase by providing the
629
721
  vocab push --branch my-branch --delete-unused-keys
630
722
  ```
631
723
 
724
+ #### Ignoring Files
725
+
726
+ The `ignore` key in your [Vocab config](#configuration) allows you to ignore certain files from being validated, compiled and uploaded.
727
+ However, in some cases you may only want certain files to be compiled and validated, but not uploaded, such as those present in a build output directory.
728
+ This can be accomplished by providing the `--ignore` flag to `vocab push`.
729
+ This flag accepts an array of glob patterns to ignore.
730
+
731
+ ```sh
732
+ vocab push --branch my-branch --ignore "**/dist/**" "**/another_ignored_directory/**"
733
+ ```
734
+
632
735
  [phrase]: https://developers.phrase.com/api/
633
736
 
634
737
  #### [Tags]
@@ -2,10 +2,11 @@ import { type UserConfig } from '@vocab/core';
2
2
  interface PushOptions {
3
3
  branch: string;
4
4
  deleteUnusedKeys?: boolean;
5
+ ignore?: string[];
5
6
  }
6
7
  /**
7
8
  * Uploads translations to the Phrase API for each language.
8
9
  * A unique namespace is appended to each key using the file path the key came from.
9
10
  */
10
- export declare function push({ branch, deleteUnusedKeys }: PushOptions, config: UserConfig): Promise<void>;
11
+ export declare function push({ branch, deleteUnusedKeys, ignore }: PushOptions, config: UserConfig): Promise<void>;
11
12
  export {};
@@ -1,2 +1,2 @@
1
- export * from "./declarations/src/index";
1
+ export * from "./declarations/src/index.js";
2
2
  //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidm9jYWItcGhyYXNlLmNqcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi9kZWNsYXJhdGlvbnMvc3JjL2luZGV4LmQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEifQ==
@@ -296,13 +296,20 @@ async function pull({
296
296
  */
297
297
  async function push({
298
298
  branch,
299
- deleteUnusedKeys: deleteUnusedKeys$1
299
+ deleteUnusedKeys: deleteUnusedKeys$1,
300
+ ignore
300
301
  }, config) {
302
+ if (ignore) {
303
+ trace(`ignoring files on paths: ${ignore.join(', ')}`);
304
+ }
301
305
  const allLanguageTranslations = await core.loadAllTranslations({
302
306
  fallbacks: 'none',
303
307
  includeNodeModules: false,
304
308
  withTags: true
305
- }, config);
309
+ }, {
310
+ ...config,
311
+ ignore: [...(config.ignore || []), ...(ignore || [])]
312
+ });
306
313
  trace(`Pushing translations to branch ${branch}`);
307
314
  const allLanguages = config.languages.map(v => v.name);
308
315
  await ensureBranch(branch);
@@ -296,13 +296,20 @@ async function pull({
296
296
  */
297
297
  async function push({
298
298
  branch,
299
- deleteUnusedKeys: deleteUnusedKeys$1
299
+ deleteUnusedKeys: deleteUnusedKeys$1,
300
+ ignore
300
301
  }, config) {
302
+ if (ignore) {
303
+ trace(`ignoring files on paths: ${ignore.join(', ')}`);
304
+ }
301
305
  const allLanguageTranslations = await core.loadAllTranslations({
302
306
  fallbacks: 'none',
303
307
  includeNodeModules: false,
304
308
  withTags: true
305
- }, config);
309
+ }, {
310
+ ...config,
311
+ ignore: [...(config.ignore || []), ...(ignore || [])]
312
+ });
306
313
  trace(`Pushing translations to branch ${branch}`);
307
314
  const allLanguages = config.languages.map(v => v.name);
308
315
  await ensureBranch(branch);
@@ -286,13 +286,20 @@ async function pull({
286
286
  */
287
287
  async function push({
288
288
  branch,
289
- deleteUnusedKeys: deleteUnusedKeys$1
289
+ deleteUnusedKeys: deleteUnusedKeys$1,
290
+ ignore
290
291
  }, config) {
292
+ if (ignore) {
293
+ trace(`ignoring files on paths: ${ignore.join(', ')}`);
294
+ }
291
295
  const allLanguageTranslations = await loadAllTranslations({
292
296
  fallbacks: 'none',
293
297
  includeNodeModules: false,
294
298
  withTags: true
295
- }, config);
299
+ }, {
300
+ ...config,
301
+ ignore: [...(config.ignore || []), ...(ignore || [])]
302
+ });
296
303
  trace(`Pushing translations to branch ${branch}`);
297
304
  const allLanguages = config.languages.map(v => v.name);
298
305
  await ensureBranch(branch);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vocab/phrase",
3
- "version": "2.0.2",
3
+ "version": "2.1.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/seek-oss/vocab.git",
@@ -17,7 +17,7 @@
17
17
  "csv-stringify": "^6.2.3",
18
18
  "debug": "^4.3.1",
19
19
  "picocolors": "^1.0.0",
20
- "@vocab/core": "^1.6.3"
20
+ "@vocab/core": "^1.6.4"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/debug": "^4.1.5",