PDA

View Full Version : Localization In Asp.net



gh_fereydonpoor
پنج شنبه 19 خرداد 1384, 08:35 صبح
سلام به همه دوستان
من داشتم می گشتم که آیا راهی داره که بشه یک سایت Multi Language داشت که با زدن یک دکمه کل صفحه ها عوض شند. مثل Localization تو VB.Net.
البته چیزی پیدا نکردم ، ولی یک روش رو Microsoft ارائه داده که با یکی از Tools هاش به نام LocalizationToolkit میشه این کارو شبیه سازی کرد.
اگر کسی اطلاعات بیشتری داره بیاد بالا صحبت کنیم.
یا علی
مرسی ممنون

titbasoft
پنج شنبه 19 خرداد 1384, 10:35 صبح
Satellite assemblies

gh_fereydonpoor
پنج شنبه 19 خرداد 1384, 16:26 عصر
بله دقیقا همون روش

Farhad.B.S
جمعه 20 خرداد 1384, 22:10 عصر
روش توکاری وجود نداره،
اما به عنوان یک راه حل معمولا تکست کنترل های موجود بر روی هر صفحه رو که قراره به طور داینامیک ست بشه در فایل های ریسورس نگهداری میکنند.
سپس یک تابع کلی نوشته میشه که با استفاده از یک حلقه ساده بین تمامی کنترل های موجود گردش میکنه و تکست کنترل مورد نظر رو پس از دریافت آن از فایل های ریسورس به کنترل نسبت میده.

gh_fereydonpoor
شنبه 21 خرداد 1384, 17:40 عصر
سلام
مرسی
بله ، این روشی که در بالا ذکر شد و دوستمان هم این روش را پیشنهاد دادند مطمئن هست؟
و آیا کلیه کنترلهای موجود را تحت پوشش قرار می دهد؟
مرسی ممنون
یا علی

titbasoft
یک شنبه 22 خرداد 1384, 12:05 عصر
ببخشید یه کم سرم شلوغ بود بخاطر همین دیر شد.
به طور خلاصه:
<p dir=ltr>
To use satellite assemblies, follow these steps:

1) Set the id and runat attributes for all of the user-interface elements of your application that require translation. Server controls have these attributes by default, but you will need to add them to HTML elements such as heading, paragraph, and span so that you can load translated strings into those elements.

2) Create a fallback resource file containing the default strings to display in the user interface if the user’s culture is not specified or not recognized. Name the fallback resource file filename.resx—for example, strings.resx.

3) Create resource files containing the translated strings to display for each general language that your Web application supports. Name the translated resource files filename.languagecode.resx—for example, strings.es.resx.

4) Optionally, create resource files containing the translated strings to display for each specific culture that your Web application supports. Name the resource file filename.languagecode-regioncode.resx—for example, strings.ex-MX.resx.

5) Write code to load the resources for the Web form using the ResourceManager class.

6)Write code to detect the user’s culture and set the Thread class’s CurrentCulture and CurrentUICulture properties to match. ASP.NET uses the CurrentCulture property to determine formatting for dates, currency, and numbers; ASP.NET uses the CurrentUICulture property to determine which satellite assembly is used when loading translated strings.

7) Write code to get strings from the resource files and display them in elements on the Web form.
</p>

یک مثال عملی:
1) ست کردن runat=server و Id برای کنترل های HTML

&lt;p id="p1" runat="server">Some introductory text.&lt;/p>

2 و 3 و 4) ساختن Resource Files
Add New Item > Resource File > type name of file :
نام فایل به صورت زیر انتخاب می شود:
الف) پیش فرض ها : assembliname.resx مثال : strings.resx
ب) یک زبان خاص: assembliname.languageCode.resx مثال: strings.fa.resx
ج) یک cultur خاص از زبان: assembliname.languageCode-regioncode.resx مثال: strings.fa-IR.resx

حالا با باز کردن هر کدام از فایل ها می تونید ترجمه هاتون رو به صورت name برای شناسایی (کلید متن) و مقدار برای آن مشخص کنید. دقت کنید که این کلید باید در کل پروژه یکتا باشد. مثلا برای مشخص کردن text یک button می توانید name را myform.mybutton.text مشخص کنید و در فیلد value ترجمه اون متن رو بنویسید مثلا : تائید در فایل asm.fa.resx و OK در فایل asm.resx

5) Loading Resource

Protected gStrings As New System.Resources.ResourceManager&#40;"PrjNamespace.strings", GetType&#40;myform&#41;.Assembly&#41;

6) Getting and Setting User-Interface Culture

private void Page_Load&#40;object sender, System.EventArgs e&#41;
&#123;
if &#40;!IsPostBack&#41;
&#123;
string sLang = Request.UserLanguages&#91;0&#93;;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture&#40;sLang&#41;;
Thread.CurrentThread.CurrentUICulture = new CultureInfo&#40;sLang&#41;;
&#125;
&#125;

7) Displaying Resource Strings

butOK.Text = gStrings.GetString&#40;"myform.mybutton.text"&#41;

(قابل ذکر که سایت titbasoft.com از همین روش استفاده می کنه)