globalizejs / globalize

A JavaScript library for internationalization and localization that leverages the official Unicode CLDR JSON data
https://globalizejs.com
MIT License
4.79k stars 605 forks source link

Feature suggestion: psuedolocalisation injection #769

Open jacalata opened 6 years ago

jacalata commented 6 years ago

I am thinking of writing a feature that would allow me to pass in a function to use on any string to pseudolocalize it (probably using /bunkat/pseudoloc), and then would (handwave) wrap the messageFormat functions for one or more locales in this function before returning them (maybe here https://github.com/globalizejs/globalize/blob/master/src/message/formatter-runtime-bind.js#L38)

Use case: I want to generate pseudoloc files on build and be able to just switch to a language I don't expect to support (e.g mongolian) to see my app in pseudo. Before I start working on this, I thought I'd check a) is this achievable today without changing the library? b) are there similar/different existing plans to enable pseudoloc?

my planned functionality setup will add this call:

    Globalize.pseudo.wrapper = function(inputStr) "[%%" + inputStr + "&&]"
    Globalize.pseudo.locale = mn_MN

messages..js will return

    Globalize.pseudo.wrapper =  function(inputStr) "[%%" + inputStr + "&&]" 
    Globalize.b588885275 = messageFormatterFn((function(  ) {
    return function (d) { return pseudo.wrapper("Hello, " + d.name;) }
    })(), Globalize("en").pluralGenerator({}));

so in my code I will have

    function Hello = Globalize.messageFormatter("Hello")
    Hello( {name: Joe} ) = "[%%Hello, Joe&&]"
WilliamHolmes commented 6 years ago

@jacalata Did you get any further with implementing a pseudo localization bundle? I was hoping to start implementing something similar to check if any strings are concatenated or hard coded etc.

Ideally, globalize would support the zz locale.

jacalata commented 6 years ago

No, I ended up finding a solution through our localization vendor software.

On Mon, Jan 15, 2018 at 4:49 AM, William Holmes notifications@github.com wrote:

@jacalata https://github.com/jacalata Did you get any further with implementation a pseudo localization bundle? I was hoping to start implementing something similar to check i any string are concatenated or hard coded etc.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/globalizejs/globalize/issues/769#issuecomment-357673838, or mute the thread https://github.com/notifications/unsubscribe-auth/AB6qeBJDTSWNGq_sJqv00zt-Vvx3kcYzks5tK0lAgaJpZM4O51Ba .

WilliamHolmes commented 6 years ago

@rxaviers I would have thought a pseudo build would be a common use case for large application builds/process. Is there any future plans or suggestions what we might do until then? I was looking as strong-globalize but I don’t want to change dependencies. Thanks.

rxaviers commented 6 years ago

It's not clear to me why this should be inside globalize instead of an independent process, e.g., by applying pseudo localization to the data itself? One can generate the JSON translations for the default locale, then create the pseudo translations for an arbitrary locale by using that. Please, could you explain?