Internationalizing a Module
Let's assume that you've gotten with the times and expanded on
your magic genie module from the "Building a Magic Genie Example
Module" in Chapter 2 to
produce a psychic module. Let's
assume that your default language is English, and you've determined
that the first additional language you should support is
Spanish.
Layout on Disk
Like any other module, your psychic readings module should simply be a source file contained in a typical directory structure:
dtdg/
psychic/
Psychic.js /* Lots of useful stuff in here */Not surprisingly, an incredible utility provided by your
psychic module is the ability to
predict the future. As such, users of your module might stick it in
a page and use it like so:
<script type="text/javascript">
dojo.require("dtdg.psychic");
dojo.addOnLoad(function( ) {
dtdg.psychic.predictFuture( );
});
</script>Although there's an awful lot of real
magic that happens in the predictFuture function, the part that
we're interested in at the moment is where a String value actually gets written to the
screen because that's where the internationalization work happens.
As it turns out, the output from your module gets written out with
the following logic:
dojo.byId("reading").innerHTML = predictFuture( /* magic */ );As a first stab at internationalization, start out with plain
old English and plain old Spanish, ignoring any particular dialects.
Given this decision, the nls
directory might look something like the following:
dtdg/ psychic/ Psychic.js ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access