Skip to content

Move constant to fix translations - #591

Merged
wojtekn merged 4 commits into
trunkfrom
fix/translations-for-site-names
Oct 11, 2024
Merged

Move constant to fix translations#591
wojtekn merged 4 commits into
trunkfrom
fix/translations-for-site-names

Conversation

@wojtekn

@wojtekn wojtekn commented Oct 10, 2024

Copy link
Copy Markdown
Contributor

Related to #416 and https://github.com/Automattic/dotcom-forge/issues/8648

Proposed Changes

I propose to move constants to function to ensure phrases are translated after translations are loaded.

Testing Instructions

  1. Switch language to other than English
  2. Add the first site, and confirm that 'My WordPress Website' gets translated
  3. Add another site and confirm that generated name is translated

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
@wojtekn
wojtekn requested a review from a team October 10, 2024 08:22
@wojtekn wojtekn self-assigned this Oct 10, 2024

@katinthehatsite katinthehatsite left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The solution works for me for the languages that use Latin characters. However, it breaks otherwise. For example, this is what happens in Russian:

First site gets created with Cyrillic characters:

Screenshot 2024-10-10 at 10 45 53 AM

Second site throws an error for the path:

Screenshot 2024-10-10 at 10 46 08 AM

This is the related issue: https://github.com/Automattic/dotcom-forge/issues/8648

I know this fixes the original issue but I am worried that it makes the user experience worse if we merge as is

@wojtekn

wojtekn commented Oct 10, 2024

Copy link
Copy Markdown
Contributor Author

@katinthehatsite it seems we need to rewrite our sanitization function. I did it in d07d306

const CHINESE = '\\u4e00-\\u9fa5';
const JAPANESE_HIRAGANA = '\\u3040-\\u309F';
const JAPANESE_KATAKANA = '\\u30A0-\\u30FF';
const KOREAN_HANGUL = '\\uAC00-\\uD7AF';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The sanitization doesn't work for a Korean as NFKD normalization removes all Korean characters, producing an empty path.

Any smart way on how to solve that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Potential ways:

  • Don't normalize string if a user uses Studio in Korean. It's an easy way, but edge cases won't work well e.g. user who uses Studio in Korean and uses Polish characters in the site name.
  • replace Korean characters with placeholders before normalization and replace them back after. It would work in all cases, but seems overly complex.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, I think we can skip normalization if Studio is in Korean.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It seems I debugged it incorrectly and came to the wrong conclusion.

Korean syllables (Hangul) are decomposed by NKFD normalization into letters (Jamo). The initial regex included only syllables, so all letters were removed. I added Korean letters to the allowed list, which now works for all cases.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix, it looks good for me now 👍

I added Korean letters to the allowed list, which now works for all cases.

Nice work!

@sejas sejas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I tested it in different languages and I confirm that all languages I tested except Korean produce a nice directory name.

As we discussed, I think the approach of not running normalization if the current Studio language is Korean is a good solution.

creating-sites-different-languages-except-korean.mp4
@wojtekn
wojtekn merged commit 2f12994 into trunk Oct 11, 2024
@wojtekn
wojtekn deleted the fix/translations-for-site-names branch October 11, 2024 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants