Skip to content

ASP.NET MVC & Javascript localization done right

Notifications You must be signed in to change notification settings

Filoni/i18N-Complete

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

i18N-Complete

ASP.NET MVC & Javascript localization done right

  • Singular
  • Plural

Singular

_, __ or ___

Quick translation in C#

//var msg = "Some message"; 

//becomes
var msg = _("Some message");

Quick translation in cshtml

<div>Some message</div>

<div>@_("Some message")</div>

_: HTML encoded format expression and arguments

Both the expression and the arguments will be HTML encodeed

@{ var names = "John&Doe"; }
<div>@_("Welcome {0}. Your age is < 100", name)</div>

//becomes
<div>Welcome John&amp;Doe. Your age is &lt; 100</div>

__: Expression can contain HTML, while arguments are HTML encoded

Make sure that you provide a valid HTML when you translate the expression

@{ var names = "John&Doe"; }
<div>@__("Welcome <b>{0}</b>. Your age is &lt; 100", name)</div>

//becomes
<div>Welcome <b>John&amp;Doe<b>. Your age is &lt; 100</div>

___: Both expression and arguments can contain HTML

This could be potentially dangerous if the arguments are not trusted i.e. come from user input such as query string, database etc. as it could lead to XSS attacks.

@{ var names = "John <i>Doe</i>"; }
<div>@__("Welcome <b>{0}</b>. Your age is &lt; 100", name)</div>

//becomes
<div>Welcome <b>John <i>Doe</i><b>. Your age is &lt; 100</div>

###Plural _s, __s, ___s

Quick translation in cshtml

//var msg = count == 1 ? "One item in the basket" : string.Format("{0} items in the basket", count); 

//becomes
var msg = _s("One item in the basked", "{0} items in the basket", count);

_s: Plural simple usage in .cshtml

@if (count == 1) {
  <div>One item in the basked</div>
}
else {
  <div>@count items in the basked</div>
}

//becomes
<div>@_s("One item in the basked", "{0} items in the basket", count)</div>

[More Documentation to be written] In the meanwhile you could also navigate to your webiste to /Localization/Help for more documentation

About

ASP.NET MVC & Javascript localization done right

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published