Skip to content

Commit 907558b

Browse files
Shinigami92ST-DDTejcheng
authored
docs: localization (#1364)
Co-authored-by: ST-DDT <[email protected]> Co-authored-by: Leyla Jähnig [email protected] Co-authored-by: Eric Cheng <[email protected]>
1 parent 8db9d6e commit 907558b

File tree

7 files changed

+37
-32
lines changed

7 files changed

+37
-32
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ Setting a new locale is simple:
121121
faker.locale = 'de';
122122
```
123123

124-
See our documentation for a list of [provided languages](https://fakerjs.dev/api/localization.html#localization)
124+
See our documentation for a list of [provided languages](https://fakerjs.dev/guide/localization.html#available-locales)
125125

126-
Please note that not every locale provides data for every module. In out pre-made locales, we fallback to english in such a case as this is the most complete and most common used language.
126+
Please note: not every locale provides data for every module. In our pre-made locales, we fallback to English in such a case as this is the most complete and most commonly used language.
127127

128128
## ⚙️ Setting a randomness seed
129129

docs/.vitepress/api-pages.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export const apiPages = [
1616
{ text: 'Helpers', link: '/api/helpers.html' },
1717
{ text: 'Image', link: '/api/image.html' },
1818
{ text: 'Internet', link: '/api/internet.html' },
19-
{ text: 'Localization', link: '/api/localization.html' },
2019
{ text: 'Lorem', link: '/api/lorem.html' },
2120
{ text: 'Mersenne', link: '/api/mersenne.html' },
2221
{ text: 'Music', link: '/api/music.html' },

docs/.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ export default defineConfig({
130130
text: 'Getting Started',
131131
link: '/guide/',
132132
},
133+
{
134+
text: 'Localization',
135+
link: '/guide/localization',
136+
},
133137
{
134138
text: 'Upgrading to v7',
135139
link: '/guide/upgrading',

docs/api/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Markdown
22
*.md
33
!index.md
4-
!localization.md
54

65
# TypeScript
76
*.ts

docs/api/localization.md renamed to docs/guide/localization.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,35 @@
11
# Localization
22

3-
As of version `v2.0.0` Faker has support for multiple localities.
3+
## Switching locales
44

5-
The default language locale is set to English.
5+
Did you know Faker supports many different locales?
6+
By default, when using `import { faker } from '@faker-js/faker'` actually every available locale that is supported by Faker will be loaded and you can switch the locale at runtime with `faker.setLocale('de')`.
67

7-
Setting a new locale is simple:
8+
::: tip
9+
Alternatively you can also just use `faker.locale = 'de'` instead to switch the locale.
10+
:::
811

9-
```js
10-
// sets locale to de
11-
faker.setLocale('de');
12-
// or
13-
faker.locale = 'de';
12+
## Individual localized packages
13+
14+
By default, Faker will include **all** locale data.
15+
This might result in loading around 5 MB of data into memory and slow down startup times.
16+
17+
_But we got your back!_
18+
When encountering such a problem in a test or production environment, you can use the individual localized packages.
19+
20+
```ts
21+
import { faker } from '@faker-js/faker/locale/de';
1422
```
1523

24+
This will then just load the German locales with additional English locales as fallback. The fallback is required due to not all locales containing data for all features. If you encounter a missing locale entry in your selected language, feel free to open a Pull Request fixing that issue.
25+
26+
::: info
27+
The English locales are around 600 KB in size.
28+
All locales together are around 5 MB in size.
29+
:::
30+
31+
## Available locales
32+
1633
<!-- LOCALES-AUTO-GENERATED-START -->
1734

1835
<!-- Run 'pnpm run generate:locales' to update. -->
@@ -78,16 +95,3 @@ faker.locale = 'de';
7895
| zu_ZA | Zulu (South Africa) |
7996

8097
<!-- LOCALES-AUTO-GENERATED-END -->
81-
82-
## Individual Localization Packages
83-
84-
As of version `v3.0.0` Faker supports incremental loading of locales.
85-
86-
By default, requiring `faker` will include _all_ locale data.
87-
88-
In a production environment, you may only want to include the locale data for a specific set of locales.
89-
90-
```js
91-
// loads only de locale
92-
const { faker } = require('@faker-js/faker/locale/de');
93-
```

scripts/apidoc.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ async function build(): Promise<void> {
3434
patchProject(project);
3535

3636
const modulesPages: PageIndex = [];
37-
modulesPages.push({ text: 'Localization', link: '/api/localization.html' });
3837
modulesPages.push(...processModuleMethods(project));
3938
modulesPages.push(...processDirectMethods(project));
4039
writeApiPagesIndex(modulesPages);

scripts/generateLocales.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* - `src/locale/<locale>.ts`
55
* - `src/locales/<locale>/index.ts`
66
* - `src/locales/<locale>/<module...>/index.ts`
7-
* - `src/docs/api/localization.md`
7+
* - `src/docs/guide/localization.md`
88
*
99
* If you wish to edit all/specific locale data files you can do so using the
1010
* `updateLocaleFileHook()` method.
@@ -25,10 +25,10 @@ const pathRoot = resolve(__dirname, '..');
2525
const pathLocale = resolve(pathRoot, 'src', 'locale');
2626
const pathLocales = resolve(pathRoot, 'src', 'locales');
2727
const pathLocalesIndex = resolve(pathLocales, 'index.ts');
28-
const pathDocsApiLocalization = resolve(
28+
const pathDocsGuideLocalization = resolve(
2929
pathRoot,
3030
'docs',
31-
'api',
31+
'guide',
3232
'localization.md'
3333
);
3434

@@ -323,13 +323,13 @@ let indexContent = `
323323
indexContent = format(indexContent, prettierTsOptions);
324324
writeFileSync(pathLocalesIndex, indexContent);
325325

326-
// docs/api/localization.md
326+
// docs/guide/localization.md
327327

328328
localizationLocales = format(localizationLocales, prettierMdOptions);
329329

330-
let localizationContent = readFileSync(pathDocsApiLocalization, 'utf-8');
330+
let localizationContent = readFileSync(pathDocsGuideLocalization, 'utf-8');
331331
localizationContent = localizationContent.replace(
332332
/(^<!-- LOCALES-AUTO-GENERATED-START -->$).*(^<!-- LOCALES-AUTO-GENERATED-END -->$)/gms,
333333
`$1\n\n<!-- Run '${scriptCommand}' to update. -->\n\n${localizationLocales}\n$2`
334334
);
335-
writeFileSync(pathDocsApiLocalization, localizationContent);
335+
writeFileSync(pathDocsGuideLocalization, localizationContent);

0 commit comments

Comments
 (0)