Westwind.Globalization
JavaScript use of resources no working
Gravatar is a globally recognized avatar based on your email address. JavaScript use of resources no working
  n/a
  All
  Sep 27, 2014 @ 03:42pm
I have followed the very simple instructions to include WW Globalization strings in Javascript (jQuery) but they are not working for me. The instructions I followed are located here.

My project is written using ASP.NET MVC5 using .NET Framework 4.5.1. Resource strings specified in the razor template render fine, but are not working in my jQuery code.

Resources.cs is contained in /Resources
~/LocalizationAdmin is installed to the default path (/LocalizationAdmin/)

WEB.CONFIG (Installation Default):

<configuration>
<system.webServer>
<handlers>
<add name="JavaScriptResourceHandler"
verb="GET"
path="JavascriptResourceHandler.axd"
type="Westwind.Globalization.JavaScriptResourceHandler,Westwind.Globalization" />
</handlers>
</system.webServer>
</configuration>

ResourceSet: Resources/Common
ResourceId: HelloWorld
Value: "Hello World"

EXAMPLE USAGE in HelloWorld.cshtml:

<div id="output_test"></div>

<script src="@JavaScriptResourceHandler.GetJavaScriptResourcesUrl("resources", "Resources/Common")"></script>

<script type="text/javascript">
$('#output_test').text(resources.HelloWorld);
</script>

Using FireFox and Firebug I do not see any errors. The handler code injected looks correct:

http://localhost:59655/JavaScriptResourceHandler.axd?ResourceSet=Resources/Common&LocaleId=en-US&VarName=resources&ResourceType=resx&ResourceMode=1

And contains:

resources = {
};

Yet, using the HelloWorld resource in the .cshtml (on the same page) like this works fine:

<div>@Common.HelloWorld</div>

Rick, you mentioned something about paths being critical. Currently, everything related to WW Globalization is installed and configured with defaults as noted above. Why is the resources var always empty? What can I try to correct this problem? What might I try to troubleshoot this problem?


Gravatar is a globally recognized avatar based on your email address. Re: JavaScript use of resources no working
  n/a
  rwkiii
  Sep 27, 2014 @ 04:37pm
It seems that the Javascript will work if I leave Resources.cs set to:

public class GeneratedResourceSettings
{
// You can change the ResourceAccess Mode globally in Application_Start
public static ResourceAccessMode ResourceAccessMode = ResourceAccessMode.AspNetResourceProvider;
}

I had tried setting ResourceAccessMode to DbResourceManager since it handles string lookups for Locales containing empty strings without causing errors.

We need to use the strings stored in the database table - we do not want to use .resx files.

I'm confused on how this should be set.

In the C# code I use DbRes.T to lookup resource strings.

In the C# razor files I have been using @ResourceSet.ResourceId

Still confused...

Gravatar is a globally recognized avatar based on your email address. Re: JavaScript use of resources no working
  Rick Strahl
  rwkiii
  Sep 27, 2014 @ 06:47pm

You'll want the .AspNetResourceProvider and set the Globalization settings in web.config to point at the custom resource provider. That will give you localized resources in all places.

The DbResourceManager mode is meant if you only use the DbRes() style operations - in that case more direct access is used that bypasses the resource provider which is slightly more efficient.

Again - I point you at the sample that comes with the library - it's set up to do what you want. It uses the resource provider and accesses both strongly typed (custom generated) resources, DbRes() resources, JavaScript resources and resource provider resources. It all works in the sample, so if you set up the resource settings the same way this should work across the entire gamut of options.

+++ Rick ---



It seems that the Javascript will work if I leave Resources.cs set to:

public class GeneratedResourceSettings
{
// You can change the ResourceAccess Mode globally in Application_Start
public static ResourceAccessMode ResourceAccessMode = ResourceAccessMode.AspNetResourceProvider;
}

I had tried setting ResourceAccessMode to DbResourceManager since it handles string lookups for Locales containing empty strings without causing errors.

We need to use the strings stored in the database table - we do not want to use .resx files.

I'm confused on how this should be set.

In the C# code I use DbRes.T to lookup resource strings.

In the C# razor files I have been using @ResourceSet.ResourceId

Still confused...



Rick Strahl
West Wind Technologies

Making waves on the Web
from Maui

Gravatar is a globally recognized avatar based on your email address. Re: JavaScript use of resources no working
  Rick Strahl
  rwkiii
  Sep 27, 2014 @ 07:01pm

Hmm... this URL is not right:


http://localhost:59655/JavaScriptResourceHandler.axd?ResourceSet=Resources/Common&LocaleId=en-US&VarName=resources&ResourceType=resx&ResourceMode=1

It shouldn't point to resx it should point to resdb. This is what I get when the resource provider is enabled:


<script src="/JavaScriptResourceHandler.axd?ResourceSet=Resources&LocaleId=de-DE&VarName=resources&ResourceType=resdb&ResourceMode=1"></script>

which I get from:


<script src="@JavaScriptResourceHandler.GetJavaScriptResourcesUrl("resources","Resources")"></script>


I suspect that's because you don't have the resource provider actually hooked up in web.config. The library looks to see if the provider is loaded and if you have it loaded it uses it. If it's not then it uses .resx.

You can try two things:
* Paste the raw <script> URL you generate above and change from Resx to resdb
* Try using the following by specifying the provider explicitly:


<script src="@JavaScriptResourceHandler.GetJavaScriptResourcesUrl("resources","Resources",null,ResourceProviderTypes.DbResourceProvider)"></script>

Notice I'm specifying the providertype explicitly in the expression.

In addition you could also hook up the resource provider in which case everything goes through the provider and the default settings are picked up by default.

+++ Rick ---



I have followed the very simple instructions to include WW Globalization strings in Javascript (jQuery) but they are not working for me. The instructions I followed are located here.

My project is written using ASP.NET MVC5 using .NET Framework 4.5.1. Resource strings specified in the razor template render fine, but are not working in my jQuery code.

Resources.cs is contained in /Resources
~/LocalizationAdmin is installed to the default path (/LocalizationAdmin/)

WEB.CONFIG (Installation Default):

<configuration>
<system.webServer>
<handlers>
<add name="JavaScriptResourceHandler"
verb="GET"
path="JavascriptResourceHandler.axd"
type="Westwind.Globalization.JavaScriptResourceHandler,Westwind.Globalization" />
</handlers>
</system.webServer>
</configuration>

ResourceSet: Resources/Common
ResourceId: HelloWorld
Value: "Hello World"

EXAMPLE USAGE in HelloWorld.cshtml:

<div id="output_test"></div>

<script src="@JavaScriptResourceHandler.GetJavaScriptResourcesUrl("resources", "Resources/Common")"></script>

<script type="text/javascript">
$('#output_test').text(resources.HelloWorld);
</script>

Using FireFox and Firebug I do not see any errors. The handler code injected looks correct:

http://localhost:59655/JavaScriptResourceHandler.axd?ResourceSet=Resources/Common&LocaleId=en-US&VarName=resources&ResourceType=resx&ResourceMode=1

And contains:

resources = {
};

Yet, using the HelloWorld resource in the .cshtml (on the same page) like this works fine:

<div>@Common.HelloWorld</div>

Rick, you mentioned something about paths being critical. Currently, everything related to WW Globalization is installed and configured with defaults as noted above. Why is the resources var always empty? What can I try to correct this problem? What might I try to troubleshoot this problem?



Rick Strahl
West Wind Technologies

Making waves on the Web
from Maui

© 1996-2024