rafikk/ply — Issue #4: Ply.res
Author: richardscarrott
Created: 2011-11-02 21:18:49+00:00
State: open

I've been using a super simple extension to Ply to help handle resource bundles within JS. Obviously the nature of Ply implies that most data will come from the server side so many resource bundles can be handled within the backend framework but there are occasions when the frontend can do with some translations. - usually just standard UI terms like close, open, show, hide etc.

I didn't like the idea of passing in the resources as options into each view as this seems to add an unnecessary restriction on where and when they can be used.

I've therefore been using the following:

/*global Ply, jQuery */
/*jshint eqeqeq: true, curly: true, white: true */

// Ply.res allows resource bundles to be defined:
//
// Ply.res({
// All: "All",
// DetailsHide: "Hide Details",
// DetailsShow: "Show Details"
// });
//
// extended:
//
// Ply.res({
// DetailsHide: "Hide",
// DetailsShow: "Show"
// Next: "Next",
// Previous: "Previous"
// });
//
// and globally accessed:
//
// Ply.res['DetailsShow'] // 'Show'
//

(function ($) {

Ply.res = function (resMap) {

$.extend(Ply.res, resMap);

return;
};

})(jQuery);

It means you could define some common bundles in your master file, then extend within each view.

Any thoughts?