epicmaxco / vuestic-ui

Free and Open Source UI Library for Vue 3 🤘
https://vuestic.dev
MIT License
3.33k stars 323 forks source link

Flatten translations #916

Closed asvae closed 2 years ago

asvae commented 2 years ago

Currently in translations we have nested collection.

That's not ideal because:

Instead we can try flat collection.

Here's an example of flat collection:

{
  "landing_header_buttons_overview": "Overview"
}

Implementation

introduce a script that

You can use yargs to introduce arguments, but generally we want this script to "somehow work", as it's probably going to be used once, then forgotten. So speedrunning this task would make the most sense.

Bonus points

m0ksem commented 2 years ago

{ "landing_header_buttons_overview": "Overview" }

We can use dots instead of underlines which is easier to copy & paste.

{
  "landing.header.buttons.overview": "Overview"
}
$t('landing.header.buttons.overview')
asvae commented 2 years ago

@m0ksem pretty sure it'll break vue i18n (it will try to resolve nested). how exactly are dots easier to copy?

mxmvshnvsk commented 2 years ago

After translating the documentation into Russian, I can highlight the following cons of flatten structure:

In general, refactoring is necessary for locales, but you might consider post-generation of a flat locale file, for example, collapse the path into a string (key).

For example:

// Convenient navigation, clear structure
{
  "shared": {
    "overview": "Overview",
    "description": "Description",
    "notification": {
      "success": "Success notification",
      "error": "Error notification"
    }
  },
  "someModule": {
    "name": "Some module name"
  }
}

// Flatten structure, difficult to search option
// You will need to keep the key pattern in mind
{
  "shared_overview": "Overview",
  "shared_description": "Description",
  "shared_notification_success": "Success notification",
  "shared_notification_error": "Error notification",
  "someModule_name": "Some module name"
}

A non-object approach is not intuitive for developers, therefore, describing translations of documentation will be annoying.

asvae commented 2 years ago

Hmm. Fair point. I guess we can just add:

And call it a day.

mxmvshnvsk commented 2 years ago

@m0ksem dot-separator difficult to understanding, because it means object path. _ and word divided by _ supported double click, it's better for Ctrl+C -> Ctrl+V =)

mxmvshnvsk commented 2 years ago

@asvae I can do this, anyway the next task is about locales.

asvae commented 2 years ago

@mxmvshnvsk sure, thanks.

Won't be able to update this issue today, but feel free to ping me in discord. :)

m0ksem commented 2 years ago

How about making a simpler file structure?

- locale
- pages
  - examples
    - example.vue
    - ...
  - page-config.ts
  - page.vue

In this case, we can add the locale files to the page. Then merge it into one global locale. This will be more complex, but we will have fewer larger locale files. I'm not sure we really need this, but it's an idea.

- locale
  // Global locales like vmodel, input, value etc.
  - en.json
  - ru.json
  - es.json
- pages
  - locale
    - en.js
    - ru.js
    - es.js 
  - examples
    - example.vue
    - ...
  - page-config.ts
  - page.vue
asvae commented 2 years ago

@m0ksem I would leave one file for now, just for ease-of-support.

We might make more translation files when docs grow up as we'd need to lazy load translations most likely.