Skip to content

Global Translations Types #1432

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

Draft
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

crhallberg
Copy link
Contributor

@crhallberg crhallberg commented May 19, 2025

Progress

  • Added a build step (hooked into build) that creates types for current English translation file.
  • Incorporated that.

TODO

  • Remove component Content types and content types from Config types.

To Discuss

  • Do we remove all component translation configs? Pros: can save something like $moreInformation to title. Cons: makes adding new translations complex, duplicate translation strings, excessive types and subtypes.

Resolves #1383.

@crhallberg crhallberg added architectural discussion DEV EX Community Sprint Developer Experience Community Sprint May-July 2025 labels May 19, 2025
Copy link

vercel bot commented May 19, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
universalviewer ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 19, 2025 4:07pm

@stephenwf
Copy link
Contributor

I think it makes sense to commit the type file, so that the types can be imported elsewhere in the codebase. It may also be worth moving it to a generated/ directory so that its clear that they shouldn't be edited - and a place for us to add more.

extension?.type.name
);

const locale = data.locales ? data.locales[0].name : defaultLocale;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const locale = data.locales ? data.locales[0].name : defaultLocale;
const locale = data.locales ? data.locales[0].name : defaultLocale.name;

Because the default locale is defined as:

export const defaultLocale = {
  name: "en-GB",
};

conf = JSON.parse(conf);

return conf;
console.log(configStr);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(configStr);

const JSONtoTS = require("json-to-ts");

class UVTranslationTypePlugin {
// Define `apply` as its prototype method which is supplied with compiler as its argument
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file seems to have tabs in it, instead of two-space indentation.

// Generate translation types

const enJSONStr = fs.readFileSync("./src/locales/en-GB.json").toString();
const enJSON = JSON.parse(enJSONStr.replace(/"\$/g, '"'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the global replacement of dollar signs? This seems to have potential for side effects. If we don't want the dollar signs, should we just remove them from the files in the first place?

Copy link
Contributor

@demiankatz demiankatz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added a couple of minor comments. I'm not sure I fully understand the implications of everything going on here -- e.g. why only process the English translations? Or is this just the first step?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking at the localeLoaders and noticed that "pl-PL" (Polski) and "sv-SE" (Svenska) aren’t listed. I hope you don’t mind me asking, are these not part of the global translation type?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LanieOkorodudu, where are they missing? I see them listed in lines 88-89 of this file. Is there somewhere else?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I just realized I may have overlooked part of the code by not expanding it fully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architectural DEV EX Community Sprint Developer Experience Community Sprint May-July 2025 discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Globally configured translations
4 participants