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

Support for Pseudolocalization? #195

Closed
danomite opened this issue May 12, 2015 · 5 comments
Closed

Support for Pseudolocalization? #195

danomite opened this issue May 12, 2015 · 5 comments

Comments

@danomite
Copy link

HI there, I am using this framework in one of my own projects and we wanted to support pseudo localization: https://msdn.microsoft.com/en-us/library/windows/desktop/dd319106(v=vs.85).aspx

To add support, I did the following, added those entries to the registry, so that CultureInfo("qps-ploc") for example generates a valid CultureInfo instantiation.

Then, I made a slight change to your regex expresssions to support 2 OR 3 character language codes in LanguageTag.cs:

   `static readonly Regex m_regex_parseLangtag = new Regex(
        @"^([a-zA-Z]{2,3})(?:-([a-zA-Z]{4}))?(?:-([a-zA-Z]{2}|[0-9]{3}))?$", 
        RegexOptions.CultureInvariant);`

    `static readonly Regex m_regex_parseUrl = new System.Text.RegularExpressions.Regex(
        @"^/([a-zA-Z]{2,3}(?:-[a-zA-Z]{4})?(?:-(?:[a-zA-Z]{2}|[0-9]{3}))?)(?:$|/)", 
        System.Text.RegularExpressions.RegexOptions.CultureInvariant);`

Then in the locales folder, you'll need to create a pseudo locale (ie, locale\qps-ploc), with a message.po file which has been pseudo localized. It helps with our localization testing as we can see right away what labels we may have missed, or code that isn't working without having to actually wait for real translations.

Just thought you might want to consider adding support for it in your code moving forward and so I can also update our framework without having to reapply the changes every time.

@turquoiseowl
Copy link
Owner

Looking at that linked document about Psuedo-Locales, it also mentions "qps-plocm" and "qps-ploca". Presumably those don't work with the above regex, so we would also need to expand the 'script' or 'region' subtags?

Any idea which actual subtag those "ploc?" elements are? That doc mentions "private use space" which suggests the private-use subtag, yet those are prefixed with "-x-" according to BCP47.

@turquoiseowl
Copy link
Owner

Elsewhere, it seems qps-plocm is in fact qps-mirr and qps-ploca is in fact qps-asia.

So if that's right (and that doc is in error) then all those will work fine with your change to the regex as it stands.

Nice idea, BTW.

@danomite
Copy link
Author

Thanks. I'm just trying to make a small contribution to this really nice project. It's much better than Microsoft's localization via resx files, which are truly painful.

I'm not completely sure about qps-plocm and qps-ploca, I ran the reg edit for just qps-ploc (you can tell it worked if you go to Control-Panel->Regions and you'll see the new Pseudo locale listed now), and then ran a powershell program (New-Object System.Globalization.CultureInfo qps-ploc) to make sure that the CultureInfo would accept the locale string since the code at some point must instantiate the CI object. When I'm at work tomorrow, I will try out qps-plocm, qps-mirr, qps-ploca and qps-asia and see what comes up. You might be right, the RegEx's may need a slight update to the script and region tags to account for them depending on what the CI object will accept.

@danomite
Copy link
Author

So today, I registered (via regedit), qps-ploca and qps-plocm. In my Control-Panel->Region->Format settings, I now have:

Pseudo Language (Pseudo)
Pseudo Language (Pseudo Mirrored)
Pseudo Language (Pseudo Asia)

If you run a Powershell, and run the following:

New-Object System.Globalization.CultureInfo qps-ploc
New-Object System.Globalization.CultureInfo qps-ploca
New-Object System.Globalization.CultureInfo qps-plocm

Those 3 lines are valid, so the code in LanguageTag will work well for those. However,

New-Object System.Globalization.CultureInfo qps-mirr
New-Object System.Globalization.CultureInfo qps-asia

Both those lines generate errors, so I don't think they will work.

You are right, the RegEx in LanguageTag will not work for those as is, so I've made the following adjustments:

static readonly Regex m_regex_parseLangtag = new Regex( @"^([a-zA-Z]{2,3})(?:-([a-zA-Z]{4,5}))?(?:-([a-zA-Z]{2}|[0-9]{3}))?$", RegexOptions.CultureInvariant);

static readonly Regex m_regex_parseUrl = new System.Text.RegularExpressions.Regex( @"^/([a-zA-Z]{2,3}(?:-[a-zA-Z]{4,5})?(?:-(?:[a-zA-Z]{2}|[0-9]{3}))?)(?:$|/)", System.Text.RegularExpressions.RegexOptions.CultureInvariant);

These now work for qps-ploca and qps-plocm as well as qps-ploc.

Also, for those people who might be following this thread. I left out a step. To my web.config, I had to add the following:

<add key="i18n.AvailableLanguages" value="en;qps-ploc;qps-plocm;qps-ploca"/>

One other unrelated thing, in EarlyUrlLocalizer, I noticed that RedirectWithLanguage is always generating a ThreadAbortException at the following line:

context.Response.End();

In my version, I've replaced it with:

context.ApplicationInstance.CompleteRequest();

Which does not generate an error. I got it from KBS: https://support.microsoft.com/en-us/kb/312629

@turquoiseowl
Copy link
Owner

Thank you for that. I've made modifications accordingly. Cheers.

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

2 participants