turquoiseowl / i18n

Smart internationalization for ASP.NET
Other
556 stars 156 forks source link

i18n on multiple projects in the same solution #360

Closed ajbeaven closed 6 years ago

ajbeaven commented 6 years ago

I've been using i18n for a while and it has been great. I'm now wanting to add i18n integration to a second website project inside the same solution.

i18n.PostBuild is set up on the Web project, with DirectoriesToScan set to the root solution folder; nuggets from all projects end up in the generated .pot file. I was hoping to have the second project, Chat, simply reference the first project's locale files.

- MySolution
    - Web
        - locale
    - Chat

Unfortunately the responses handled by Chat come through with the nugget markup visible, so something somewhere is broken. When I use HttpContext.ParseAndTranslate nuggets are successfully translated. There was no change when I copied the Web locale folder to Chat and referenced that as the LocalDirectory.

The Web project does not use OWIN but Chat does. Chat uses SignalR.

Here are my config files for the Chat project.

Startup.cs

public void Configuration(IAppBuilder app)
{
    // ...

    // i18n config
    i18n.LocalizedApplication.Current.DefaultLanguage = "en";
    i18n.UrlLocalizer.UrlLocalizationScheme = i18n.UrlLocalizationScheme.Scheme2;

    // i18n middleware
    app.Use(typeof(i18n.Adapter.OwinSystemWeb.UrlLocalizationMiddleware));

    // i18n response filter installer for static files
    var staticFileOptions = new StaticFileOptions
    {
        OnPrepareResponse = (staticFileResponseContext) =>
        {
            if (staticFileResponseContext.File.Name.EndsWith(".js", StringComparison.OrdinalIgnoreCase))
            {
                HttpContextBase context = staticFileResponseContext.OwinContext.Get<HttpContextBase>(typeof(HttpContextBase).FullName);
                i18n.LocalizedApplication.InstallResponseFilter(context);
            }
        }
    };
    app.UseStaticFiles(staticFileOptions);
}

Global.asax

protected void Application_ReleaseRequestState(object sender, EventArgs e)
{
    HttpContextBase context = this.Request.GetOwinContext().Get<HttpContextBase>(typeof(HttpContextBase).FullName);
    i18n.LocalizedApplication.InstallResponseFilter(context);
}

Web.config

<add key="i18n.DirectoriesToScan" value=".." />
<add key="i18n.WhiteList" value="*.cs;*.cshtml;*.js;*.sitemap;*.html" />
<add key="i18n.LocaleDirectory" value="../Web/locale" />

Any suggestions? Is the OWIN integration confirmed to be working as it should? Presumably this scenario with multiple projects is supported?

ajbeaven commented 6 years ago

Oh, and running i18n in debug showed output for the HttpContext.ParseAndTranslate translation but nothing for the others.

Static file compression is turned off, though it shouldn't affect the specific translations I'm trying to see as they're coming through from SignalR.

ajbeaven commented 6 years ago

Hmm, I think the issues I'm experiencing are due to the change in #334.