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

Cleanup translations and remove Turkish & Greek #1135

Merged
merged 17 commits into from
Oct 10, 2023

Conversation

LukasKalbertodt
Copy link
Member

@LukasKalbertodt LukasKalbertodt commented Oct 5, 2023

Fixes #1075

This moves around translations (i.e. giving them a different key), mostly to transition to the nested form. This PR also removes unused translations. Not all keys are in the nested form yet as I lost motivation at this point some are just used in several places and don't fit well into the nested structure. Finally, Greek and Turkish are removed. See the relevant commit for more info.

This is quite a big and annoying-to-review PR, unfortunately. I don't think a code review is useful or necessary:

  • Thanks to Typescript, every translation key used in code is checked against en.json. Thus, all used translation keys at least exist in the English file!
  • Locally, with a few quick'n'dirty scripts, I made sure that all other JSON files only contain a subset of the keys of the English file. (See scripts below)
  • I am very sure that I didn't accidentally remove translations while moving them around.
  • To check whether a translation is unused, it is not sufficient to just grep its key. In code, we sometimes use something like t(`foo-${yes ? "cat" : "dog"}`). Which Typescript is able to understand, but grep doesn't of course. So for those false positives "unused" translations I checked again manually. And again: I can't accidentally remove one that is still used, as Typescript will complain.

I already asked and will still ask a few contacts to provide full translations for French, Farsi, Spanish, Chinese simplified. Those will be added in a follow up PR.


My used scripts, just for reference:

flatten.ts: prints the flat translation keys of a JSON file. Run with deno --allow-read flatten.ts -- path/to/file.

const flatten = (obj: object, prefix: string) => {
  for (const key in obj) {
    if (isObject(obj[key])) {
      flatten(obj[key], `${prefix}${key}.`);
    } else {
      console.log(`${prefix}${key}`);
    }
  }
};

const isObject = (v: unknown): v is object => (
  typeof v === "object" && !Array.isArray(v) && v !== null
);


const filename = Deno.args[1];
const content = await Deno.readTextFile(filename);
const jsonIn = JSON.parse(content);
flatten(jsonIn, "");

Run that for en.json and save to enkeys.txt. Then run this script on the output of flatten.ts for all other files:

#!/bin/bash

while IFS= read -r line
do
    rg -q "$line" ./enkeys.txt || echo "$line"
done

These are removed from other languages later!
The English word was "back", so using `prev` is a bit weird. The type
in code wasn't changed though.
These transitioned already into the "nested style". Instead of just
removing all old ones, we move them to preserve the translation.
Don't know how that happened, wupps.
Both languages had a super low translation percentage with most strings
missing. I also don't currently see who could improve the situation. So
removing them for now, keeping the few translations in git history. At
some point, we will use Crowdin again, hopefully somewhat improving that
situation. Farsi has even fewer translated strings, but a colleague
(Farbod) offered help in that regard, so keeping for now.
@LukasKalbertodt LukasKalbertodt changed the title Cleanup translations Cleanup translations and remove Turkish & Greek Oct 5, 2023
@owi92 owi92 merged commit fa09899 into elan-ev:master Oct 10, 2023
2 checks passed
@LukasKalbertodt LukasKalbertodt deleted the cleanup-translations branch October 10, 2023 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cleanup translations (remove unused strings, move stuff around, remove almost dead languages)
2 participants