You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+53-19Lines changed: 53 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -208,20 +208,70 @@ const props = defineProps<{
208
208
209
209
Ideally, extract utilities into separate files so they can be unit tested. 🙏
210
210
211
+
## RTL Support
212
+
213
+
We support `right-to-left` languages, we need to make sure that the UI is working correctly in both directions.
214
+
215
+
Simple approach used by most websites of relying on direction set in HTML element does not work because direction for various items, such as timeline, does not always match direction set in HTML.
216
+
217
+
We've added some `UnoCSS` utilities styles to help you with that:
218
+
219
+
- Do not use `left/right` padding and margin: for example `pl-1`. Use `padding-inline-start/end` instead. So `pl-1` should be `ps-1`, `pr-1` should be `pe-1`. The same rules apply to margin.
220
+
- Do not use `rtl-` classes, such as `rtl-left-0`.
221
+
- For icons that should be rotated for RTL, add `class="rtl-flip"`. This can only be used for icons outside of elements with `dir="auto"`.
222
+
- For absolute positioned elements, don't use `left/right`: for example `left-0`. Use `inset-inline-start/end` instead. `UnoCSS` shortcuts are `inset-is` for `inset-inline-start` and `inset-ie` for `inset-inline-end`. Example: `left-0` should be replaced with `inset-is-0`.
223
+
- If you need to change the border radius for an entire left or right side, use `border-inline-start/end`. `UnoCSS` shortcuts are `rounded-is` for left side, `rounded-ie` for right side. Example: `rounded-l-5` should be replaced with `rounded-ie-5`.
224
+
- If you need to change the border radius for one corner, use `border-start-end-radius` and similar rules. `UnoCSS` shortcuts are `rounded` + top/bottom as either `-bs` (top) or `-be` (bottom) + left/right as either `-is` (left) or `-ie` (right). Example: `rounded-tl-0` should be replaced with `rounded-bs-is-0`.
225
+
211
226
## Localization (i18n)
212
227
213
228
npmx.dev uses [@nuxtjs/i18n](https://i18n.nuxtjs.org/) for internationalization. We aim to make the UI accessible to users in their preferred language.
214
229
215
230
### Approach
216
231
217
232
- All user-facing strings should use translation keys via `$t()` in templates and script
218
-
- Translation files live in `i18n/locales/` (e.g., `en.json`)
219
-
- We use the `no_prefix` strategy (no `/en/` or `/fr/` in URLs)
233
+
- Translation files live in `i18n/locales/` (e.g., `en-US.json`)
234
+
- We use the `no_prefix` strategy (no `/en-US/` or `/fr-FR/` in URLs)
220
235
- Locale preference is stored in cookies and respected on subsequent visits
221
236
237
+
### Adding a new locale
238
+
239
+
We are using localization using country variants (ISO-6391) via [multiple translation files](https://i18n.nuxtjs.org/docs/guide/lazy-load-translations#multiple-files-lazy-loading) to avoid repeating every key per country.
240
+
241
+
The [config/i18n.ts](./config/i18n.ts) configuration file will be used to register the new locale:
242
+
243
+
-`countryLocaleVariants` object will be used to register the country variants
244
+
-`locales` object will be used to link the supported locales (country and single one)
245
+
-`buildLocales` function will build the target locales
246
+
247
+
To register a new locale:
248
+
249
+
- for a single country, your JSON file should include the language and the country in the name (for example, `pl-PL.json`) and register the info at `locales` object
250
+
- for multiple country variants, you need to add the default language JSON file (for example for Spanish, `es.json`) and one of the country variants (for example for Spanish for Spain, `es-ES.json`); register the language at `countryLocaleVariants` object adding the country variants with the JSON country file and register the language at `locales` object using the language JSON file (check how we register `es`, `es-ES` and `es-419` in [config/i18n.ts](./config/i18n.ts))
251
+
252
+
The country file should contain will contain only the translations that differ from the language JSON file, Vue I18n will merge the messages for us.
253
+
254
+
To add a new locale:
255
+
256
+
1. Add a new file at [locales](./i18n/locales) folder with the language code as the filename.
257
+
2. Copy [en](./i18n/locales/en.json) and translate the strings
258
+
3. Add the language to the `locales` array in [config/i18n.ts](./config/i18n.ts), below `en` and `ar`:
259
+
- If your language has multiple country variants, add the generic one for language only (only if there are a lot of common entries, you can always add it as a new one)
260
+
- Add all country variants in [country variants object](./config/i18n.ts)
261
+
- Add all country variants files with empty `messages` object: `{}`
262
+
- Translate the strings in the generic language file
263
+
- Later, when anyone wants to add the corresponding translations for the country variant, just override any entry in the corresponding file: you can see an example with `es` variants.
264
+
- If the generic language already exists:
265
+
- If the translation doesn't differ from the generic language, then add the corresponding translations in the corresponding file
266
+
- If the translation differs from the generic language, then add the corresponding translations in the corresponding file and remove it from the country variants entry
267
+
4. If the language is `right-to-left`, add `dir` option with `rtl` value, for example, for [ar](./config/i18n.ts)
268
+
5. If the language requires special pluralization rules, add `pluralRule` callback option, for example, for [ar](./config/i18n.ts)
269
+
270
+
Check [Pluralization rule callback](https://vue-i18n.intlify.dev/guide/essentials/pluralization.html#custom-pluralization) for more info.
271
+
222
272
### Adding translations
223
273
224
-
1. Add your translation key to `i18n/locales/en.json` first (English is the source of truth)
274
+
1. Add your translation key to `i18n/locales/en.json` first (American English is the source of truth)
225
275
2. Use the key in your component:
226
276
227
277
```vue
@@ -267,22 +317,6 @@ We recommend the [i18n-ally](https://marketplace.visualstudio.com/items?itemName
267
317
268
318
The extension is included in our workspace recommendations, so VSCode should prompt you to install it.
269
319
270
-
### Adding a new locale
271
-
272
-
1. Create a new JSON file in `i18n/locales/` (e.g., `fr.json`)
0 commit comments