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

inject or overwrite translations #413

Open
Roman991 opened this issue Sep 17, 2019 · 7 comments
Open

inject or overwrite translations #413

Roman991 opened this issue Sep 17, 2019 · 7 comments

Comments

@Roman991
Copy link

Roman991 commented Sep 17, 2019

I cant find a way to overwrite translations, ex:
req.('foo) => 'BAR'
what I'm trying to do is, for certain routes, to overwrite the value of 'foo' from 'BAR' to 'BAZ'
kinda
req.
('foo) = 'BAZ'

@mashpie
Copy link
Owner

mashpie commented May 3, 2020

sry... I don't get your use case or context

@imagoiq
Copy link

imagoiq commented May 4, 2020

One of the use cases would be to force a certain typesetting.

For example in French, there is a thin non-breakable space before ? and ! which is problematic as this doesn't exist in our keyboard. People are just putting normal space and it often happens that these characters are finding themselves alone in a new line. One way to prevent it, it would be to replace the space with a Unicode characters.

See here for greater explanation and example: kazupon/vue-i18n#318

@mashpie
Copy link
Owner

mashpie commented May 4, 2020

Example is about dealing with special chars... i18n supports full unicode so shouldn't be problem to just enter any [space] or [opt+space]   or let's say "minus" - vs. "dash" directly into translation files. I have no idea about a non breaking space equivalent in unicode though. How is this handled in editors or office apps?

edit: see wikipedia for Keyboard entry methods https://en.wikipedia.org/wiki/Non-breaking_space

What I still don't understand is "...a way to overwrite translations..." ???


the vue-i18n issue seams more related to #365

@imagoiq
Copy link

imagoiq commented May 4, 2020

Please read my last answer of kazupon/vue-i18n#318

It's kind of UX issue with translators. Either you have a good process, people respect it and add correct unicode characters in the strings or you don't have any of that and you want to be sure that the strings are well standardized.

@mashpie
Copy link
Owner

mashpie commented May 4, 2020

so you request a feature likepostTranslation https://kazupon.github.io/vue-i18n/api/#posttranslation right?

as a hint it is easy to "decorate" req in an express based app and wrap existing methods like so (not tested):

// init i18n before any other decoration
app.use(i18n.init)

// define postprocessor
const postTranslation = (str) => str.replace(' ?', '\xa0?').replace(' !', '\xa0!')

// decorate...
app.use((req, res) => {

  // add a postprocessed version of __()
  req.pp__ = (...args) => postTranslation(req.__(args))
  
})

Still imaginable to get such added as configurable option in future

Note to myself could be added as optional function in here

var postProcess = function(msg, namedValues, args, count) {

@mashpie
Copy link
Owner

mashpie commented May 4, 2020

...you want to be sure that the strings are well standardized.

Just a thought: Shouldn't this be a preProcessor before getting added to translation dictionaries rather than a postProcessor - maybe within a QA stage? ;) - but hey post or pre, now I get it.

@imagoiq
Copy link

imagoiq commented May 4, 2020

Thanks for the example and your reflexion. Surely, you are right, this should be part of a preproduction process, but I think that some small projects will benefit from such feature. I do think it should be a standard option even if we can replicate easily.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants