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

feat(i18n): use same languages names in display and translations sections (settings/language) #2817

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

userquin
Copy link
Member

@userquin userquin commented Apr 14, 2024

This PR includes a new virtual module to use it instead iso-639-1 dependency: since translations showing only configured languages in conf/i18n.ts module, we just use them via the virtual module.

We cannot remove iso-639-1 dependency, it is being used in composables/language.ts (also renamed) and publish widgets (languages and fuse).

We can decide if we change the languages names to use Intl.DisplayNames/iso-639-1 ones: for example including only country names when added to the country variant entry in conf/i18n.ts module.

Language Names with Country Variants in Firefox

imagen

console.table([ 'ar-EG',
  'ca-ES',
  'ca-valencia',
  'ckb',
  'cs-CZ',
  'de-DE',
  'en-GB',
  'en-US',
  'es-419',
  'es-ES',
  'eu-ES',
  'fa-IR',
  'fi-FI',
  'fr-FR',
  'gl-ES',
  'hu-HU',
  'id-ID',
  'it-IT',
  'ja-JP',
  'ko-KR',
  'nl-NL',
  'pl-PL',
  'pt-BR',
  'pt-PT',
  'ru-RU',
  'th-TH',
  'tl-PH',
  'tr-TR',
  'uk-UA',
  'vi-VN',
  'zh-CN',
  'zh-TW'
].reduce((acc, l) => {
  acc[l] = new Intl.DisplayNames(
    [l],
    { type: 'language', languageDisplay: 'standard', localeMatcher: 'lookup' },
  ).of(l)
  return acc
}, {}))

closes #2814

Copy link

stackblitz bot commented Apr 14, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

netlify bot commented Apr 14, 2024

Deploy Preview for elk-zone ready!

Name Link
🔨 Latest commit d141985
🔍 Latest deploy log https://app.netlify.com/sites/elk-zone/deploys/661be1d453a31900086cdeb6
😎 Deploy Preview https://deploy-preview-2817--elk-zone.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Apr 14, 2024

Deploy Preview for elk-docs canceled.

Name Link
🔨 Latest commit d141985
🔍 Latest deploy log https://app.netlify.com/sites/elk-docs/deploys/661be1d4c64ed20008c74013

@userquin
Copy link
Member Author

Maybe we can use use locales from useI18n() directly...

@userquin userquin marked this pull request as ready for review April 14, 2024 14:12
Copy link
Member

@shuuji3 shuuji3 left a comment

Choose a reason for hiding this comment

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

I just noticed that we can use lang+country code (e.g. en-US) for the "Display Language" section but we should use only lang code (e.g. en) without country variants for the "Hide Translation" setting.

Before

see: https://main.elk.zone/settings/language

Screenshot from 2024-04-15 22-27-19
Screenshot from 2024-04-15 22-34-55

After

see: https://deploy-preview-2817--elk-zone.netlify.app/settings/language

Screenshot from 2024-04-15 22-32-29


This is because Mastodon's status object only has two characters of lang code such as en and es so we can only filter by lang code.

ref. Status - Mastodon documentation - https://docs.joinmastodon.org/entities/Status/#language

example:

{
  ...
  id: "112225445529039980",
  content: "<p>Hello</p>",
  language: "en",
  media_attachments: [],
  ...
}

@shuuji3
Copy link
Member

shuuji3 commented Apr 15, 2024

Maybe we can use use locales from useI18n() directly...

If this can simplify code, maybe it's a good idea?

@shuuji3
Copy link
Member

shuuji3 commented Apr 15, 2024

Also, do we want to use the new function getDisplayName() in the "Display Language" section too?

<template>
<select v-model="userSettings.language">
<option v-for="item in locales" :key="item.code" :value="item.code" :selected="userSettings.language === item.code">
{{ item.name }}
</option>
</select>
</template>

+import { getDisplayName } from 'virtual:iso-639-1'

...

-       {{ item.name }} 
+       {{ getDisplayName(item.code) }}

@userquin userquin marked this pull request as draft April 15, 2024 13:58
@userquin
Copy link
Member Author

userquin commented Apr 15, 2024

Also, do we want to use the new function getDisplayName() in the "Display Language" section too?

No, those locales come from conf/i18n.ts module and so the name is the name configured there.

@shuuji3
Copy link
Member

shuuji3 commented Apr 15, 2024

OK, will we adjust countryLocaleVariants in config/i18n.ts after this change? I thought using the same method could provide consistent naming instead of hardcoding.

@shuuji3
Copy link
Member

shuuji3 commented Apr 22, 2024

We could also consider other languages in the "Hide translation" list (please refer to #2843). Although there is no need to include them in this PR, it may affect how we organize the language names.

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.

Language naming issue at Hide translation block
2 participants