Overview

Introduction

Globsite.Globalization is a library dedicated to improving and simplifying globalization of ASP.NET applications.
The package contains the database resource provider model, which allows you to store resources in the database in an easy and straightforward way.
Because the library extends the ASP.NET Resource-Provider Model, the standard, comfortable convention of using resources in .NET applications is still available.

Main Features

By storing resources in the database they are easily editable and multiple third-party tools can be used to manage the process of localization and to change resource values without further compilations.

Strongly Typed Resources functionality is provided with an easy to use T4 template.

Configuration is very flexible and powerful, but also simplified and intuitive.

Return values for not found resources can be customized and means problems with a standard NULL value are avoided.

Automatic creation of a database table for resources using a T4 Template is provided, meaning freedom from manual execution of SQL scripts.

All resources are stored in a consistent manner, in a single database table.

The ability to use an independent database to store resources (e.g. the database is shared with some other applications).

Stored strings can be of any length and contain any characters.

Getting and setting of a current culture for the application is easier.

Access to resources may be case sensitive or insensitive.

Enables management resources and working collaboratively with translators using a dedicated online tool: Globsite.net.

Missing resources can be created automatically, when they are required for the application.

Effective loading mechanism due to resources being loaded only once for each set and each culture. Resources are also loaded only when they are actually needed, which prevents excessive usage of the application memory.

The installation process is simple and can be provided by a NuGet package.

The name of a resource table in the database can be customized (e.g. in the case of naming conflicts).

The process of generating Strongly Typed Resources' classes is customizable.

Installation

NuGet Package

The easiest way to install the library in your project is to install the NuGet package: https://www.nuget.org/packages/Globsite.Globalization.Mvc

To install the library package, run the following command in the Package Manager Console

PM> Install-Package Globsite.Globalization.Mvc

Manual Installation

You can manually attach the library to the project by downloading the appropriate files.

  • Runtime binary (Globsite.Globalization.Mvc.dll) must be referenced in the project.
  • Some configuration will be needed, for details look at the configuration section.
    Alternatively a configuration transformation file (Web.config.install.xdt) can be used.
  • For Strongly Typed Resources functionality the T4 Template (Resources.tt) must be included in the project.
Downloads (Globsite.Globalization.Mvc 1.1.3):

Configuration

Parameters Specification

The table presents available configuration parameters.

Key Required Value Type Default Value Description
connectionStringName Yes string   Name of the connection string to database with the resource table.
resourceTableName No string Resources Name of the resource table in database.
ignoreCase No bool false Indicates if resources (keys and sets) should be case insensitive.
createResourceIfNotExists No bool true Indicates if resources should be automatically created if missed (but used in the code).
missingResourceValue No string formatted with variables:
${Null}, ${StringEmpty}, ${ResourceKey}, ${ResourceSet}, ${CultureCode}
${StringEmpty} Defines a return value in case of a missing resource. If createResourceIfNotExists parameter is set to true, this setting defines a value of the automatically created resource.
NOTE: Variable ${Null} is not permitted if createResourceIfNotExists is set to true.
T4 Template
T4_resourceClassName No string Resources Defines a class name, which encapsulates resources for each resource set (for Strongly Typed Resources).
T4_namespacePrefix No string   Defines a prefix for namespaces of created classes (for Strongly Typed Resources). Namespaces are built with the prefix and set names.
NOTE: If empty, the default project namespace will be set as a prefix.
T4_createResourceTableIfNotExists No bool true Indicates if the resource table should be created automatically in database if not exists yet.
NOTE: In case of resource table will be created by the T4 Template this setting will be set to false automatically.

Sample Configuration

The snippet presents a sample configuration (e.g. ~\Web.config) for the library.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="globsite" type="Globsite.Globalization.Mvc.GlobsiteConfigSection, Globsite.Globalization.Mvc, Version=1.1.1.0, Culture=neutral, PublicKeyToken=ac8682b66182f424" />
  </configSections>
  <connectionStrings>
    <add name="GlobsiteConnection"
         connectionString="Data Source=(localdb)\Projects;Initial Catalog=SampleDatabase;Integrated Security=True;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False"
         providerName="System.Data.SqlClient" />
  </connectionStrings>
  <globalization resourceProviderFactoryType="Globsite.Globalization.Mvc.DbResources.DbResourceProviderFactory, Globsite.Globalization.Mvc, Version=1.1.1.0, Culture=neutral, PublicKeyToken=ac8682b66182f424" />
  <globsite>
    <dbResources
      connectionStringName="GlobsiteConnection"
      resourceTableName="Resources"
      ignoreCase="false"
      createResourceIfNotExists="true"
      missingResourceValue="${StringEmpty}"
      T4_createResourceTableIfNotExists="true"
      T4_resourceClassName="Resources"
      T4_namespacePrefix="" />
  </globsite>
  <!-- Some additional configurations here... -->
</configuration>

Examples

View Source Code

The snippet presents a sample Razor view (e.g. ~\Views\Home\Index.cshtml), where different localization approaches have been used.

@using System.Globalization
@using Globsite.Globalization.Mvc.DbResources
@*Define the resource set for the file*@
@using SampleWebsite.Home

<div class="jumbotron">
    <h1>Globsite.Globalization.Mvc</h1>
    <p>
        Globalization package for MVC applications.
        The package contains the database resource provider model,
        which allows you to store resources in a database in a really easy way.
    </p>
</div>

<div>
    <hr />
    <h4>Using Strongly Typed Resources</h4>
    <hr />
    Resource Value (currently included namespace/set):
    @Resources.HelloWorld
    <hr />
    Resource Value (explicitly specified namespace/set):
    @SampleWebsite.Home.Index.Resources.IndexTitle
    <hr />
    Current Set Name:
    @Resources.Set
    <hr />
    @{Resources.Culture = new CultureInfo("es-ES");}
    Explicitly Declared Culture:
    @Resources.Culture
    <hr />
    <h4>Using Resource Helper</h4>
    <hr />
    Resource Value (explicitly specified set):
    @DbRes.GetString("HelloWorld", "Home")
    <hr />
    Resource Value (explicitly specified set and culture):
    @DbRes.GetString("HelloWorld", "Home", "de")
    <hr />
    <h4>Using Extensions</h4>
    <hr />
    Resource Value Using HtmlHelper Extension:
    @Html.GetString("HelloWorld", "Home")
    <hr />
    @{ Utils.CurrentUICulture = new CultureInfo("de-DE"); }
    Explicitly Changed UI Culture:
    @Utils.CurrentUICulture
    <br />
</div>

Sample Resources

The table contains sample resources which can be placed in the database to play with different sets, keys, cultures and values.

Set Key CultureCode Value
Home HelloWorld   Hello World!
Home HelloWorld de Hallo Welt!
Home HelloWorld es-ES Hola Mundo!
Home.About AboutTitle   About Title
Home.About AboutTitle de About Titel
Home.About AboutTitle es-ES About título
Home.Index IndexTitle   Index Title
Home.Index IndexTitle de Index Titel
Home.Index IndexTitle es-ES Index título

Rendered View

The image presents a view localized with the source code and sample resources listed above.

Rendered View

Resource Management

The resource management method for the project depends on a few factors, e.g.

  • the size of the project (resources, languages, translators),
  • how often resources are modified (added, edited, deleted),
  • who manages the resources (developer, some technical person or translators directly).

The primary way for developers to manage resources, available during application development, is to use any database management tool.
Below are some examples of popular tools:

A convenient way to manage resources in an application and also the whole localization process is to use our dedicated software, available here.
This tool allows you to manage resources, browse project statistics with progress and online collaboration with translators. Just register an account and create your first project. You can import/export resources to/from your application with a simple wizard - using ResX files or Globsite.Globalization database. In the second case, the database should be available for remote connections.
The full list of the available features can be found here.

License

The library is free for both private and commercial use. The library is licensed with GNU Lesser General Public License (LGPL).

Roadmap

  • Q1 2017
    • MySQL integration - allowing to store resources in MySQL database.
    • Visual translations - allowing to view a context of website resources.
  • Q2 2017

    Coming soon...