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

Translation of units into different languages #126

Open
andresgutgon opened this issue Aug 4, 2021 · 0 comments
Open

Translation of units into different languages #126

andresgutgon opened this issue Aug 4, 2021 · 0 comments

Comments

@andresgutgon
Copy link

andresgutgon commented Aug 4, 2021

Hi, first of all thanks for this. Is super helpful and looks super complete!

I was reading the issues and search in all repo but I didn't see any references to localization. Is there something related with the translation of the units?

Could be a translations folder. And people could initialize like formatter

import enLocale from 'qt/translations/en.json'
import esLocale  from 'qt/translations/es.json'
const LOCALES = {
  en: enLocale,
  es: esLocale
}
function init (locale: string) {
  Qty.translations =  LOCALES[locale] || LOCALES.en
}

Then you can pass the type of format. We could have long/short format. And also take into account plurals. 1 meter vs 2 meters

I would introduce a new method to

new Qty(1, 'm').localizedFormat({ format: 'long' }) 
// 1 meter

// Change to Spanish
Qty.translations =  LOCALES.es 

new Qty(2, 'm').localizedFormat({ format: 'long' }) // you can omit "targetUnit" if you want the same
// 2 metros
new Qty(2, 'm').localizedFormat({ targetUnit: 'cm', format: 'long' }) 
// 200 centímetros

// Short version by default
new Qty(2, 'm').localizedFormat({ targetUnit: 'cm' }) 
// 200 cm

I realize maybe what I want is doable by myself with Qty.formatter but I think could be nice to have these translations in the repo shared and maintained by the community.

What do you think? : )

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

No branches or pull requests

1 participant