-
Notifications
You must be signed in to change notification settings - Fork 156
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
Stream processing #37
Comments
I tried that in the beginning by using the CodeDom and actually parsing out The idea to intercept incoming HTTP traffic is a creative one. If it's It might be a lot of effort, but I can see the value of not having to think On Thu, Jan 31, 2013 at 4:16 PM, Martin Connell [email protected]:
|
First attempt at doing this: It's been working well so far with early testing. An HttpModule needs to be installed in web.config like this:
Uses regex to lookout for 'nuggets' in the html or javascript matching the pattern:
If found, extracts the msgid from within the braces and replaces the entire nugget with the result of a GetText call. Outstanding issues on which I'd welcome input:
Point 2. is making me nervous for it may require route localization to be moved out of MVC into another HTTP module/filter. Cheers Martin |
Moving everything out to a filter may not be all bad. But it requires some Using a module to tag external resource URLs for localization is no problem On Fri, Feb 1, 2013 at 10:52 AM, Martin Connell [email protected]:
Daniel Crenna |
Another thing that I've thought of is that this approach will not allow you to see potential unclosed string tags at compile time, which is very useful, specially if you are doing complex HTML in the middle |
Thanks Raul. By string tags, do you mean the [[[ and ]]] markers (or whatever we might finalize on)? |
@daniel, my assumption was that we (you :) ) would use Regex to parse Javascript in the PO build phase, in fact with the same pattern as used in the response filter as they are both doing the same job. But I'm assuming the user edits the Javascript sources so as to decorate the target strings, thus have their own versions of jquery.validate or whatever. Or are you thinking of extracting undecorated strings from Javascript? |
Self-install of the module = sweet. |
Update on progress with the HTTP module: Following on from the idea to move more out to it, the module facilitates two functions: Nugget Localization - The translation of 'nuggets' (e.g. [[[Translate me!]]]) which are in the HTTP response entity body and for one reason or another were not translated earlier on in the ASP.NET pipeline. The notable example of this is with DataAnnotations, but may also include Javascript and any other enabled content type. For example, I have a model property annotated like this:
The [[[User Name]]] nugget is picked up in the response entity and with the result of calling GetText("User Name"). The choice of markers is user configurable, but needs to correspond to the markers used by the xgettext/postbuild generator (which remains outstanding work). URL Localization - This is the localization of URLs by the HTTP Module. A request's URL is processed early in the pipeline in order to derive the principal language for the request (this is called Early URL Localization). Any langtag in the URL is then stripped off so as not to bother the app with it. The app can read the principle language from and HttpContext extension method. This includes the GetText language matching algorithm. Early URL Localization may cause a redirect from a nonlocalized URL to a localized one, according to a scheme setting. It can also be disabled entirely to support consistent URLs regardless of principal user language. As an optimization, URL Localization also supports patching of outgoing URLs found in the response entity where appropriate. This patching converts nonlocalized same-host URLs to a localized form e.g. example.com -> example.com/fr. This avoids an unnecessary redirect should the user agent subsequently request the URL. A regex is used to do this. It works well for me, so far, but is configurable and may be disabled if so desired. Other features:
Changes to initializationHere's an example of what an Application_Start may contain:
I intend to back off the v2.0 branch now for a while. The Nugget Localization feature is dependent on xgettext/postbuildtask support for it which I understand others will do. If not, please let me know and I'll get onto it as I need it for my project. My testing has been limited to a small website; it should be tested with a larger site (which I do not have at present) before being released. If this work is accepted, there will then be some redundant stuff in there related to MVC route localization and action filter to lop out. Regards Martin Connell |
Added support for formatted nuggets which enables more sophisticated DataAnnotations:
The syntax is like this:
valn is a runtime value stuffed into the nugget and picked up by the post processor for the replacement of a corresponding %n identifier in the canonical msgid. So in the post-processing of nuggets:
PO Generation NotesThe parser for PO file generation needs to extract the canonical msgid from the nugget and output that. Some experimentation with xgettext -a (extract all strings) has successfully managed to extract the nuggets from .cs, .cshtml and .js files. Output of that is suitable as input to a nugget parser. |
Great job |
@raulvejar Thanks for your feedback. Just testing :) and well spotted, it should be %1. I'll edit it. |
Nice work. I'll attempt to get caught up on all of this over the next D. On Wed, Feb 6, 2013 at 12:03 PM, Martin Connell [email protected]:
|
@danielcrenna Thanks, sounds good, very happy to answer questions etc. |
I've been trying to work out how to localize DataAnnotations, jQuery.validation stuff etc. and had an idea:
Is there scope in i18n for general processing of the HTTP response output and making translation there. E.g. we could scan for msgids wrapped in some markers like ###Translate me!###, lookup any corresponding message and, if found, swap it in.
Maybe this has already been thought of, or is not practical?
About to go away and investigate ASP.NET HttpModules/Handlers... I guess it would also require xgettext or equivalent to be able to locate these marked strings in the project source.
The text was updated successfully, but these errors were encountered: