An open API service indexing awesome lists of open source software.

https://github.com/metlinskyi/web-forms

The proof of concept of asp.net web-forms localization approach
https://github.com/metlinskyi/web-forms

asp-net csharp webforms

Last synced: 22 days ago
JSON representation

The proof of concept of asp.net web-forms localization approach

Awesome Lists containing this project

README

          

# Asp.Net Web Froms Localization

The proof of concept application with demonstration of localization for Asp.Net Web Froms.
The main target is to minimize the copying of a code.

#### Web.config

Set a default culture.

```XML


```

Set extend Asp.Net localization controls.

```XML


```

#### Literals

Create culture resource files.

```
.
+-- App_GlobalResources
| +-- UI.resx // default resource
| +-- UI.es-US.resx // localized resource
```

Use the expression builder in the ASP.NET Web Form page.

```ASP

```

#### Routing

Set culture routing handler in RouteConfig.cs

```C#
var handler = new CultureRouteHandler("culture", "page")
{
WebRoot = "~/Pages/",
};

routes.Add(new Route(string.Empty, handler));
routes.Add(new Route("{culture}/{*page}", handler));
```

Different culture pages.
When the route handler does not find a specific culture page, then system will get a common page.

```
.
+-- Pages
| +-- Account.aspx // common page
| +-- Account.es-US.aspx // specific page
```

Use links with {culture} tag.
All values of 'href' or 'src' attributes with {culture} tag will be replaced to current culture.

```ASP

```

#### UI

Different culture templates on a page.
If the Localization control does not find a specific culture template, then a default template will be rendered.

```ASP






```

Different culture templates of UserControl.
If a UserControl does not find a specific culture template, then a default template will be rendered.

```
.
+-- Controls
| +-- UserProfile.ascx // common control template
| +-- UserProfile.es-US.ascx // specific control template
```

#### Performance

All searching process results will be cached, for example:

```C#
// Trying to find a valid template path in a cache.
var key = string.Concat(culture, AppRelativeVirtualPath);
var appRelativeVirtualPath = Cache[key] as string;
if (string.IsNullOrEmpty(appRelativeVirtualPath))
{
// The template path not found in cache, creating a new template path with current culture.
appRelativeVirtualPath = AppRelativeVirtualPath.Replace(".ascx", $".{culture}.ascx");

try
{
// Trying to load the localized template.
template = LoadTemplate(appRelativeVirtualPath);
Cache[key] = appRelativeVirtualPath;
}
catch
{
// The localized template not found, will be use default.
Cache[key] = appRelativeVirtualPath = AppRelativeVirtualPath;
}
}
```

 
============
© [The Best Software Engineer In The Universe!](https://www.linkedin.com/in/metlinskyi/)