1

Im pretty much stuck, because i cant figure out how to "call" resource files in .js files. I have a login view, on this view i call MVC render method to generate script tag.

   @Scripts.Render("~/Scripts/Login.js")

in my Login.js i have a variable :

var yes = "Resources.Resource.Yes";

which should be tranlated to Yes, or Ja, or anything else depends on which cultureInfo is set. Its pretty straight forward to do if i keep script files inside of my view, because then i just call @Resources.Rescource.Yes and it will work, but if script file is external, then it wouldnt work. How do i solve this?

2
  • How do you want to solve it? I.e. "~/Scripts/Login.de-de.js" with localized text? Commented Jan 3, 2015 at 8:29
  • I don't think it's possible, you should try to find 3d party libraries that support are localized, support i18n integration or any other localization mechanism. If they don't, then you will have to write the wrapper of the library on your own Commented Jan 3, 2015 at 9:45

1 Answer 1

2

The answer to this question would be largely opinion-based.

There are three main approaches i encountered working on various projects:

  1. Localization handlers. You define the resources keys in javascript, in $(document).ready() you use ajax to get the localized values from a controller/httphandler dedicated to this and replace keyed text.
  2. In-line js. Basically, you dump external .js and render scripts inside <script> tags in your views/pages.
  3. Global variables. In the view your define global variables, like so:<script language="text/javascript">var myString='<%= Resources.MyString %>';</script>, then use the variable inside included .js.

Personally i prefer approach n 3 -> you can have a single place in code to create all variables and the page loads in one go.

Sign up to request clarification or add additional context in comments.

1 Comment

i chose third approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.