Using .Net Resources in Javascript

Internationalization can be tricky, to say the least.

For .Net, you have some good tooling in place to help you create and edit resource files, which can provide text and images that can be used to support an internationalized application. But when I tried to internationalize the javascript side of an application, I didn’t find anything that looked like it would work for us.

I had been working on an ASP.Net MVC application, and I was already using .Net resource files for internationalization on the .Net side. I wanted to leverage the existing .Net resource files, because there was already a workflow for keeping them up to date and there was a good amount of text already translated that I wanted to make use of. And I wanted this data available in Javascript, because part of the application was written in Javascript.

Here is what my javascript initially looked like before internationalization:

1
$('#status').text("Hello World!");

The text, being hardcoded in my javascript file, was clearly not internationalized.

Read More

Caching with Rails

When working with rails, it’s quite useful to change a source file, save it, and reload a web application merely by refreshing the web browser. This had been working great, until one day when my changes didn’t appear in the browser.

I tried clearing the cache on the browser, but it didn’t help. Only when I restarted rails would the change get picked up. Considering that this took a good bit longer than simply refreshing the browser, this caused a serious drain on my productivity and warranted an investigation.

After some initial searching, I discovered the config.cache_classes setting. Here is how the documentation describes it:

config.cache_classes controls whether or not application classes and modules should be reloaded on each request. Defaults to false in development mode, and true in test and production modes. Can also be enabled with threadsafe!.

That sounded promising - all I had to do was disable caching. I went back to development.rb, and here is what I saw:

1
config.cache_classes = false

Caching was already disabled. But Rails still seems to be caching. What’s going on? After reading a blog post by Aaron Patterson, things made a little more sense.

Read More

.Net Extended Framework

The framework is split. Some parts of .Net are included in the normal .Net Framework. But some features are only found in the Extended / Full .Net Framework.

I ran into this when testing an update to a WinForms application that I was working on. The app worked great in production, but once we moved it to the testing environment, this error popped up:

Could not load file or assembly ‘System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’ or one of its dependencies. The system cannot find the file specified.

Read More

Unapparent Parent in Knockout Binding Context

When working with KnockoutJS, the with binding allows you to change the current binding context. So if you have a nested data structure, instead of having to binding to properties such as subViewModel.property1 and subViewModel.property2, you can put them inside a with binding and then refer to them directly as property1 and property2, respectively.

This is quite useful in keeping your views from getting too cluttered when your viewmodel structure gets large. However, if you jump down more than one level in a single the with binding, it’s not immediately apparent what the $parent context will refer to.

Read More