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
- Host: GitHub
- URL: https://github.com/metlinskyi/web-forms
- Owner: metlinskyi
- Created: 2019-07-19T11:50:44.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-08-20T12:42:29.000Z (almost 2 years ago)
- Last Synced: 2024-08-20T14:44:05.941Z (almost 2 years ago)
- Topics: asp-net, csharp, webforms
- Language: JavaScript
- Homepage:
- Size: 959 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
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.
#### 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/)