Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate the translation of code-snippets inside the website/i18n folder to new string interpolation mechanism #3338

Closed
rrousselGit opened this issue Feb 11, 2024 · 3 comments · Fixed by #3408
Assignees
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed

Comments

@rrousselGit
Copy link
Owner

Background

In https://riverpod.dev website, code snippets are plain .dart files that are then imported using the syntax:

import myCodeSnippet from "!!raw-loader!./path/to/coode_snippet.dart";

Then passed to <CodeBlock/>/<CodeSnippet/>/<AutoSnippet/>.

An example can be found here:

For the page https://riverpod.dev/docs/concepts/about_code_generation, the source can be found at:

import autoDisposeCodeGen from "!!raw-loader!./about_codegen/provider_type/auto_dispose.dart";

This line imports the following file:
https://github.com/rrousselGit/riverpod/blob/a54f32fec6207873377bc665dad1b11fa2106bb9/website/docs/concepts/about_codegen/provider_type/auto_dispose.dart

The file imported is then later used here:

<CodeBlock language="dart">{trimSnippet(autoDisposeCodeGen)}</CodeBlock>

When it comes to translating the file, translations duplicate the .dart files and edit the comments
to the new language.
For example, a variant of the previous code-snippet can be found in Korean here:
https://github.com/rrousselGit/riverpod/blob/master/website/i18n/ko/docusaurus-plugin-content-docs/current/concepts/about_codegen/provider_type/auto_dispose.dart

Task

Moving forward, we would want translations to stop duplicating the original .dart files.
Instead, a string interpolation mechanism has been put in place.

The idea is to insert inside the English code-snippet some keys.
An example can be found here: https://github.com/rrousselGit/riverpod/blob/master/website/docs/advanced/select/select_async/raw.dart#L16

Then, translations should no-longer duplicate the English file.
Instead, they should import the original English file.
For example, here is the Korean translation importing the English code snippet:

import selectAsync from "/docs/advanced/select/select_async";

The imported file is then used slightly differently. It is now inserted in the document with an extra parameter, corresponding to a map of translations:

Notice how the key passed in the translation object corresponds to the name of the "template" in the code snippet ({@template watch})

The goal is to apply this logic to all code-snippets in the website folder.

@rrousselGit rrousselGit added documentation Improvements or additions to documentation help wanted Extra attention is needed good first issue Good for newcomers labels Feb 11, 2024
@rrousselGit rrousselGit self-assigned this Feb 11, 2024
@vchrisb
Copy link

vchrisb commented Mar 3, 2024

@rrousselGit it looks like the templating isn't yet working?
When opening https://riverpod.dev/docs/advanced/select, with "code generation" disabled, the site renders:

final provider = FutureProvider((ref) async {
  // {@template watch}
  // Wait for a user to be available, and listen to only the "firstName" property
  // {@endtemplate}
  final firstName = await ref.watch(
    userProvider.selectAsync((it) => it.firstName),
  );

  // {@template todo}
  // TODO use "firstName" to fetch something else
  // {@endtemplate}
});

The same happens for local development.

@rrousselGit
Copy link
Owner Author

Funky, looks like a bug. Not sure how that slipped by

@rrousselGit
Copy link
Owner Author

Translations should be working again

@rrousselGit rrousselGit linked a pull request Mar 10, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants