Giter Site home page Giter Site logo

localization's Introduction

Localization

Create multi-language structure with ASP.NET MVC

PM> Install-Package Localization

Usage

- <li>@Html.ActionLinkLocalization("English", "Index", "Locales", new { lang = "en_US" })</li>
- <li>@Html.ActionLinkLocalization("Türkçe", "Index", "Locales", new { lang = "tr_TR" })</li>
and more...
Or
- <a href="Locales/?lang=en_US">English</a>
- <a href="Locales/?lang=tr_TR">Türkçe</a>
and more...

Index.cshtml

@Html.Get("homepage") or @Html.Localize("homepage")

Video Tutorial

ASP.NET MVC Localization Tutorial vimeo

ASP.NET MVC Localization Tutorial youtube

Requirements

Localization

  • en_US.xml
  • tr_TR.xml
  • and more...

Bin

  • Insya.Localization.dll
  • System.ComponentModel.DataAnnotations

Structure

Views

Xml file
<item id="homepage">Home Page</item>

Razor
     @Html.Localize("homepage")
     Or
     @Html.Get("homepage")
  
Code Behind
     Localization.Localize("homepage")
     Or
     Localization.Get("homepage")

@Html.ActionLinkLocalization()
@Html.ActionLocalization()

Inline Localization

@Html.Get(new Inline(en: "book", tr: "kitap"))
@Html.Localize(new Inline(en: "book", tr: "kitap"))

Controllers

public ActionResult Index(string lang = "en_US")
{
  Response.Cookies["CacheLang"].Value = lang;
  
  if (Request.UrlReferrer != null)
  Response.Redirect(Request.UrlReferrer.ToString());
  
  var message = Localization.Get("changedlng");
  
  return Content(message);
}

Models

Attribute Localize
  Display Attribute 
    [DisplayLocalize("username")]
    public string Username { get; set; }
  
  String Length Attribute 
    [StringLengthLocalize(20, MinimumLength = 4)]
    public string DisplayName { get; set; }
  
  Required Attribute 
    [RequiredLocalized]
    public string DisplayName { get; set; }
  
  Description Attribute 
    [DescriptionLocalize]
    public string DisplayName { get; set; }

Intellisense in razor files (Views/web.config)

  • Views
    • web.config
      • system.web.webPages.razor
        • pages
          • namespaces
            • add namespace="Insya.Localization"
            • add namespace="Insya.Localization.Helpers"

Example

<system.web.webPages.razor>
  <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <pages pageBaseType="System.Web.Mvc.WebViewPage">
          <namespaces>
          <add namespace="System.Web.Mvc" />
          <add namespace="System.Web.Mvc.Ajax" />
          <add namespace="System.Web.Mvc.Html" />
          <add namespace="System.Web.Optimization"/>
          <add namespace="System.Web.Routing" />
          ## <add namespace="Insya.Localization" />
          ## <add namespace="Insya.Localization.Helpers" />
          </namespaces>
      </pages>
</system.web.webPages.razor>

Note: Nuget package auto insert

Contribution

Fork

Roadmap:

  • Localizable Routing
  • All the XML language files editing tool on one screen.
  • Testing tools

localization's People

Contributors

rosselm avatar yasinkuyu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.