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: docs/localization.md
+71Lines changed: 71 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,3 +32,74 @@ Both of these routes use the [TutorialsLayout](/src/layouts/TutorialsLayout.astr
32
32
The main difference between these two routing files is how they retrieve the correct translation. The English version retreives the English version of the content. The other translations retrieve their version of the content and then fill in any gaps with English versions. See `getCollectionInLocaleWithFallbacks()` for how this works.
33
33
34
34
Because of this subtle duplication, we try to keep the files in `src/pages/` as short as possible and move rendering logic into the [layout files](/src/layouts/).
35
+
36
+
## Using translations
37
+
38
+
When you are editing an existing page or adding a new one, there are two ways to use individual translated strings from the ["ui" content collection](/src/content/ui/). It depends on what kind of file you are editing:
39
+
40
+
### Astro files (`.astro`)
41
+
42
+
In .astro files you can use `getCurrentLocale()` and `getUiTranslator()` like so:
43
+
44
+
```astro
45
+
---
46
+
import { getCurrentLocale, getUiTranslator } from "@i18n/utils";
`getCurrentLocale()` extracts the current locale code from the page's URL. Passing this to `getUiTranslator()` tells it which language to return translations for. Whenever a translation is missing for the given language, it will return the string in English (the fallback language).
58
+
59
+
The returned translator function (`t`) accepts a key or list of keys to know which translation string to return. Check [the English translation file to see the most complete list of what's already available](/src/content/ui/en.yaml). The keys you pass to the translator function are used to lookup a string in that file (or the equivalent of it in the current language). If the `en.yaml` file has the following content:
60
+
61
+
```yaml
62
+
Forum: Forum
63
+
Sketches: Sketches
64
+
Libraries: Libraries
65
+
People: People
66
+
New intro paragraph: Welcome to this new page we just added!
67
+
sectionTitles:
68
+
main: An intro to squares
69
+
```
70
+
71
+
Then `t("New intro paragraph")` will return "Welcome to this new page we just added!" and `t("sectionTitles", main)` will return "An intro to squares".
72
+
73
+
### Preact files (`.jsx`, `.tsx`)
74
+
75
+
Preact files cannot access the current url directly with `Astro.url.pathname`, so we have to take a different approach: we pass in a translation object as a prop. Every Preact component in this project is rendered from an Astro layout or component file, so we can rely on it to get the correct current language.
76
+
77
+
In our astro file, we use our old friend `getCurrentLocale()` and then pass the result to `getUiTranslationWithFallback()` to get an object of translations. And pass it to the `HelloButton` component.
78
+
79
+
```astro
80
+
---
81
+
import { getCurrentLocale, getUiTranslationWithFallback } from "@i18n/utils";
82
+
import { HelloButton } from "@components/HellowButton/index.jsx"
Essentially, the arguments you would pass to `t` in the first example for astro files are the same you would pass as keys to the `uiTranslations` object. If its a nested key, that looks like:
This repo includes a few scripts to pull content from external sources, primarily the [p5.js repo](https://github.com/processing/p5.js).
4
4
5
5
They are all runnable via npm scripts.
6
6
7
-
## Search Indices Build Script
7
+
## After a p5.js release
8
8
9
-
`npm run build:search` generates metadata about the content of the website so the search functionality can show relevant results.
9
+
To update the content on the p5.js website following a new release of p5.js, you should run all of these commands to pull in the latest content. **Be sure to run the search indices script last as it depends on the results of the other scripts to be accurate.**
10
10
11
11
## Contributor Docs Build Script
12
12
13
-
`npm run build:contributor-docs` copies the contributor docs from the p5.js website repo and places them into the [contributor docs content collection](/src/content/contributor-docs).
13
+
`npm run build:contributor-docs` copies the contributor docs from the p5.js repo and places them into the [contributor docs content collection](/src/content/contributor-docs).
14
14
15
15
## Reference Build Script
16
16
@@ -19,3 +19,7 @@ They are all runnable via npm scripts.
19
19
## Contributors List Build Script
20
20
21
21
`npm run build:contribtuors` parses the list of contributors from the all contributors [config file](https://github.com/processing/p5.js/blob/main/.all-contributorsrc) in the p5.js repo and adds entries in the [people collection](src/content/people/en) for anyone who is missing. These are used to render the list of contributors on the [People page](https://p5js.org/people/). This script will **not** remove or update existing entries, that must be done manually.
22
+
23
+
## Search Indices Build Script
24
+
25
+
`npm run build:search` generates metadata about the content of the website so the search functionality can show relevant results. This script should usually be run after any of the above scripts are run.
Copy file name to clipboardExpand all lines: docs/technical_overview.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,8 @@ The website code is divided into a few main folders:
28
28
-`src/components/` holds UI elements that are rendered on different pages of the website. Things like basic buttons, as well as more specialized things like the top navigation menus are here.
29
29
-`src/layouts/` this contains the basic visual structure of each page. If you are looking to edit a specific page of the website, finding the layout for it in this folder is a great place to start.
30
30
-`src/pages/` these files are primarily used to create the routes (the different URLs) for the pages of the website and pull content from `src/content/`. Note that every route basically exists twice: once in `src/pages/` and again in `src/[locale]/pages/` to support localized urls. Read more about this in [./localization-architecture.md]
31
+
-`src/api/` holds the logic for fetching information from the OpenProcessing API, where all the gallery sketches for this website are stored
32
+
-`src/i18n/` holds the utilities and configuration for working with translations
31
33
-`src/scripts/` contains utility scripts that update the files in `src/content/` with changes in the p5.js repo
32
34
-`styles/` contains globally applied css styles for the website
33
35
-`test/` contains a set of unit tests that cover some important utility functions and key components
0 commit comments