I would like to be able to internationalize a backbone + Handlebars application but I am not clear what the best way to do it. Are there any specific best practices for internationalizing backbone + Handlebar views?
On the server side I am using SpringMVC and have access to standard java internationalization facilities.
Here are some very good resources on internationalization for the client side.
http://2012.jsconf.eu/speaker/2012/08/28/client-side-internationalization.html really worth watching it provides a good explanation of the issues with internationalization and is java-script focused.
http://alexsexton.com/blog/2012/03/the-ux-of-language/ Good article about the internationalization
JavaScript libraries for internationalization:
https://github.com/SlexAxton/messageformat.js
http://slexaxton.github.com/Jed/
Standards:
http://userguide.icu-project.org/formatparse/messages (very useful read)
http://cldr.unicode.org/ (more of a reference)
Currently I'm working with an app with (very limited) internationalization, and I mix in an object with the model before sending it to the template in the Backbone.Marionette.Renderer.render function. If you have a similar central function which renders your templates (which I assume you have) you can do this logic there. You could for instance mix the internationalized content (language preselected in) in a namespace, for instance
data = _.extend(model, {t: translations(:dutch))
Leaves how to get the translations from the backend to the frontend, but I don't know enough of SpringMVC to give you advise on that.
We use i18next (http://i18next.com) in our Require/Backbone/Handlebars app with very good results. It supports plural and context forms and there are converters from PO to JSON and vice versa. (PO is widely used for translations here.) The documentation is clean and full of helpfull examples.
It's possible to use it in Handlebars with both static keys (strings) or dynamic variables. You will have to setup your own Handlebars helpers but the documentation of i18next provides example code for this.
In this post, I've added more implementation details:
https://stackoverflow.com/a/17728920/621690
Related
I am using coverity for java static code analysis, I need to add some custom rules so that scan happens according to the custom rule set.
Yes, you can write custom rules with Coverity. There are two APIs you can use:
"Extend" is the older API. Extend rules are written in C++ (regardless of what language you are scanning).
"CodeXM" is the newer API. CodeXM is a domain-specific language designed for writing static analysis rules.
Both APIs are explained in the product documentation, although that is not publicly available. My recollection is both APIs support the same set of scanned languages, specifically, C, C++, Java, and Javascript.
There are a couple Synopsys blog posts about CodeXM that might help you get started:
Getting started with writing checkers using CodeXM
Let’s write a CodeXM checker (it’s not rocket science!)
Additionally, as noted in an answer to How can we add custom rules for coverity tool?, sometimes the customization you want to do can be accomplished simply by changing the options to existing checkers. (I do not consider this question to be a duplicate of that one because the other question seems to be more about adjusting the behavior of existing checkers, despite its title.)
Disclosure: I'm a former Coverity/Synopsys employee.
Right, so, if I was simply using Titanium, I could write:
var platino = require("co.lanica.platino");
And I'd be good to go. Since moving to Alloy, I don't know how to replicate the same line in the afforementioned MVC framework.
Do I add it under the global namespace? I already added the module in tiapp.xml, but I have no idea how to access it as a variable "platino".
The docs for Alloy are pretty sparse...any suggestions?
Require method is almost same in Alloy, you can use the require keyword in your js file and implement as in classic approach.
checkout the docs.
I'm conducting a project in which a website should have multi-language support.
Now, this website is supposed to serve about 500K+ visitors a day, so it must be super-efficient.
I've created a table of parameters {[ID],[Name]} AND a linkage-table {[objectID],[parameterID],[languageID],[value]}. I think it's the best way to deploy multi-language support while having the privilege to translate different parameters for each language.
As far as I know, server's memory is much faster than a physical HDD. Therefore, I'm planning to store ASP.NET Application State objects for my translation architecture.
(http://msdn.microsoft.com/en-us/library/ms178594.aspx)
How does my plan sound so far? any suggestions?
If you are planning on making an app that support multiple languages, your instant reflex should be let .net do the work for you. What i'm reading in your question is that you are setting up something to support that. You should know that localization is the way to go when you want to develop a multi-language environment.
Take a look at this msdn article, it should give you a general idea on the topic.
So, localizing an application can be divided into two parts:
Localizing business logic entities.
Localizing everything else.
In the question I see words which are related to business entity localization. For that purpose I agree with the concept to have separation between entities and their localizations.
Part 1 - Localizing entities:
Personally I do this way in database:
table Entity {EntityID, Name} -this is the entity-related table.
table EntityByLang {EntityID, LanguageID, Name} -this is the localized version of the table for each supported language.
This way allows me to have default values for each localizable property like Name and its localization, if such is available in the localized table. What's left here up to you is - you need to implement the data-access-layer which takes the Name localized for the current user language, or the default value (if language or the translation is not available for the given language).
Part 2 - Localizing everything else:
Here, with no alternatives in terms of the performance, I would recommend using some kind of static resources. Personally I live with static resources available for standard asp.net applications.
From the architectural point of view, don't directly refer to localization code from your UI code, like this (which I don't like):
var translation = HttpContext.Current.GetGlobalResourceObject("hello");
//excuse me, if I don't exactly remember the GetGlobalResourceObject() method name...
Instead, I would recommend using this kind of approach:
var translation = AppContext.GetLocalizationService().Translate("hello");
Where: AppContext - some kind of facade/factory (in fact, implementation of abstract facade/factory). GetLocalizationService - initially returns some kind of ILocalizationService, when implemented it returns StaticResLocalizationService (which implements ILocalizationService). This way allowing switching from one kind of localization to another. And particularly StaticResLocalizationService works with asp.net static resources
Sorry for messy sample codes, but I hope you understand my approach.
I hope this helps!
I would suggest to create custom resource provider, you can read more here:
http://msdn.microsoft.com/en-us/library/aa905797.aspx
with this model you can leverage existing asp .net localization functionality
As the question is a bit self explanatory, I want to achieve the goal of a multi-language website. I am using an Entity Data Model with MS SQL 2005. I came up with an idea of making a seperate database for each language with exactly the same model and relations. So I can use the Entities constructor that takes a connectionString and switch the site to the selected language.
I am using an ascx as the language control that fires an event, and the parent aspx gets the selected language as an integer (from event args) and call the method containing the same linq queries but Entity context will be created with the connection string of that db (of language)
I could only came up with this solution, because I think adding a new language will require a replication of the english one, imported to Access and sent to the translator. Then will be exported back, and the model will fit (HOPEFULLY).
My question is if this is really a good approach or am I missing anything that will create greater hassle to me. Thanks in advance
multi-database is not a good solution as soon as entities within the different databases have relations to each other. Generally a good approach is to work with labels in one default language. These labels can either be in a well defined format (e.g. 'LABEL.TEXT_HELLO') or just in the base language (e.g. 'Hello World').
So all you have to do is building a table for translations where the base language is the key and hopefully there is for each key a value containing the translation. As soon as you have the translations, you can write a method ont he frontend which writes the labels in the language used by the user.
In Zend Framework for example, you have to write <h1><?= $this->translate('Hello World'); ?></h1> instead of just <h1>Hello World</h1>
The good thing about that is, that if ya translation is missing, you can still use the fallback (in this case english) to show the user at least something.
That way, you can manage your app in one database and users who speak several languages do not have to switch between applications and content.
cheers
My approach: create a table Language that lists all the available languages. Relate each table that should be localized to Language. Now, you can easily access the localized content e.g.
Content[content_ID].HeadLine.Where(hl => hl.Language.id == "en-US")
I look forward to see what other people as I myself is still learning DB design and EDM.
OK, if you want to be able to easily implement a new language, then reinventing the internationalization features already built in to ASP.NET is not the way to go, because it isn't "easy".
At least, not as easy as using a satellite resource DLL. Your translators will use off-the-shelf tooling to translate your resources, and ASP.NET will automatically select the correct DLL based on the user's current culture.
Read up on ASP.NET internationalization/globalization features; there's no need to invent your own.
I am creating a web application that will need to send a variety of emails out to users. Instead of hard-coding the contents of the email in the app, I want to use a template stored on disk and replace tokens in it (ex. "Hello, %%FirstName%%!") with the actual data. I have some experience with creating XSLT templates, but since the data isn't naturally in XML format this may not be the best fit. Is there a better template tool in .NET?
Note that I prefer one built in to the language but I'd consider add-ons too.
Thanks,
Graham
I have personally use Spark. Its an easy to use text templating library (below is an example of Spark syntax)
<var names="new [] {'alpha', 'beta', 'gamma'}"/>
<for each="var name in names">
<test if="name == 'beta'">
<p>beta is my favorite.</p>
<else/>
<p>${name} is okay too I suppose.
</test>
</for>
It even comes with a sample code for email text templating which you could look at on github.
You may want to take a look at MVCContrib. They have an e-mail template system IEmailTemplateService that uses Views to render the actual e-mail message which gives you access to a lot of features, including different view engines. If you are not in an MVC environment, you could possibly still extract some useful tricks out there.
I am using NVelocity for that, and I find it's very flexible and easy to use. It not only allows you to replace tokes, but it also includes sort of a programming language, e.g. for conditionals (if) and loops (for, foreach).
The original project seems to be dead, but there is a fork maintained by the Castle project.
Of course there are lots of other, alternative template libraries (stringtemplate seems to be popular), as you can see in this question I asked some time ago.