윈도우 앱개발을 향하여

블로그 이미지
윈도우 10 스토어에 앱을 개발해 올리는 것을 목표로 하고 있습니다. 비전공자가 독학으로 시도하는 일이어서 얼마나 걸릴지 모르겠지만... 아무튼 목표는 그렇습니다!!
by 코딩하는 경제학도
  • Total hit
  • Today hit
  • Yesterday hit

Copyright

이 모든 내용은 Pluralsight에 Jeremy Clark가 올린 'Localization and Globalization in .NET'라는 강의의 첫번째 챕터를 듣고 정리한 것입니다(https://app.pluralsight.com/library/courses/intro-to-localization-globalization-dotnet/table-of-contents).


Content

1. Fundamentals

2. Considerations

3. Globalization



Definitions

Localization

The process of adapting an application so that its resources can be replaced at runtime.

(Language, region, culture etc... => strings, images)


Globalization

The process of engineering an application so that it does not have cultural preconceptions.

(DateTime, number, currency, calendars formats etc... => cultural formatting and other things)


Internationalization

The process of localizing and globalizing an application



.NET Localization Support

CultureInfo object (specify a language or both language and culture) (link)

Use this in conjunction with Resource files to create localized strings and images for application

These get compiled into satellite assemblies, and are used based on the culture values of the current thread.


CultureInfo(string name)

virtual string Name { get; }

virtual DateTimeFormatInfo DateTimeFormat { get; set; }

virtual NumberFormatInfo NumberFormat { get; set; }

virtual Calendar Calendar { get; }

virtual Calendar[] OptionalCalendars { get; }

virtual bool IsNeutralCulture { get; }

A neutral culture is one that specifies a language, but not a country or region.

e.g., en is neutral culture, en-US is specific culture


Neutral Cultures still have date time and number formatting information

Formatting and other values are set based on the defaults for the language

e.g., The default values for the English language are based on US English. Warning


static CultureInfo InvariantCulture { get; }

We can create an invariant culture by using an empty string for the CultureInfo constructor.

e.g., var invariantCulture = new CultureInfo("");


Or, can use the static InvariantCulture property on the CoultureInfo object

e.g., var invariantCulture2 = CultureInfo.InvariantCulture;


Invariant Culture is designed for things that should not change with culture

It can be use to persist data in culture-independent format

Invariant Culture is associated with the English language but no culture or region


#so There is neutral culture, specific culture, and invariant culture


static CultureInfo CurrentCulture { get; set; }

Gets or sets the System.Globalization.CultureInfo object that represents the culture used by the current thread


static CultureInfo CurrentUICulture { get; set; }

Gets or sets the CultureInfo object that represents the current user interface culture used by the Resource Manager to look up culture-specific resources at run time



Culture List in MSDN



Resource

Any non-executable data that is logically deployed with an app, including strings, images, and persisted objects.


.NET offers several ways to handle resources.

We will use resx file, or resw file(for UWP)

This gives us a centralized place to put localized strings.

.resx or .resw file contains value withh Name(key), value whill be displayed in our application.

Create culture-specific resource files and set Name-Value pair


Using Resource

WPF XAML

<TextBlock Text="{x:Static resx:Resources.Customer_Customer}" ..../>

ASP.NET MVC Markup

<td>@MVCOrderTaker.Resources.Home.Index.Customer_Customer</td>

C# Code

ProductName = Properties.Resources.Product_UniversalTranslator;




Satellite Assemblies

The compiler generates satellite assemblies.


hub-and-spoke model (image)




Thread and Culture

class Tread : ...

public static Tread CurrentThread { get; }

public CultureInfo CurrentCulture { get; set; }  //Determines globalization, formats(data, number, currency), sorting calendars etc

public CultureInfo CurrentUICulture { get; set; }

//Determines which set of Resources are used in the UI

//So, if the CurrentUICulture is set to US English, it will look for the resource assembly that has the same designation

...


Both of these properties are setable, this means that we can change the culture programmatically.

#There is exception for Windows Store Apps


CurrentCulture

For .NET 4.0 or later, this can be specific culture or neutral culture

Prior to .NET 4.0, this must be a specific culture (no neutral cultures allowed)

Is we only have a neutral culture we can call the CreateSpecificCulture method

var specficCulture = CultureInfo.CreateSpecificCulture("en")

Either way, if we use the neutral "en" culture, we will end up with a specific en-US culture


The reason we need a specific culture is that CurrentCulture...

Determines globalization formats for dates, numbers, and currency

Determines the sort order (how accented, or capitalized characters)

Determines parsing (such as DateTime.Parse)

Determines output formats such as DateTime.ToString("d")


Note : most parsing and output methods take an optional IFormatProvider parameter.


CurrentUICulture

Determines which culture-specific resources are used

This is how the resource manager knows which of the satellite assemblies should be used at run time

CurrentCulture can be a neutral or specific culture


CurrentCulture & CurrentUICulture

CurrentCulture and CurrentUICulture are almost always set to the same culture

This will make sure that we have consistency across our application

But they can be set to different values to support special cases.

e.g., French languages in US, "fr-US" does not exist

CurrentCulture = "en-US" to get US formatting (dates, currency)

CurrentUICulture = "fr" to get French language resources


e.g., create custom cultures



How does Culture Get Set?

Thread.CurrentTread.Current(UI)Culture = ??? Where is it come from?


CultureInfo.DefaultThreadCurrentCulture { get; set; }

CultureInfo.DefaultThreadCurrentUICulture { get; set; }


CultureInfo has static "Default" properties, both properties's default values are null

When set, these values are used for all new threads created in the application domain


When a thread is started, its Thread.CurrentThread.Current(UI)Culture is set to the DefaultThreadCurrent(UI)Culture.

If null, Current(UI)Culture is set based on the OS culture


Meaning, if we do nothing, we get the OS culture by default for desktop apps

For web apps, culture is based on the request header


Both CurrentCulture and CurrentUICulture properties on the Thread class are writable

This means that we can manually set the culture if we like as hardcoded value or value from configuration, or user preference setting in our database.

(하지만 UWP에선 Thread class에 접근할 수 없다.)


e.g., var culture = new CultureInfo("cs-CZ");

Thread.CurrentThread.CurrentCulture = culture;

Thread.CurrentThread.CurrentUICulture = culture;


//Use the same culture for any newly created threads

CultureInfo.DefaultThreadCurrentCulture = culture;

CultureInfo.DefaultThreadCurrentUICulture = culture;



Summary (생략)


출처

이 모든 내용은 Pluralsight에 Jeremy Clark가 올린 'Localization and Globalization in .NET'라는 강의의 첫번째 챕터를 듣고 정리한 것입니다(https://app.pluralsight.com/library/courses/intro-to-localization-globalization-dotnet/table-of-contents). 제가 정리한 것보다 더 많은 내용과 Demo를 포함하고 있으며 최종 Summary는 생략하겠습니다. Microsoft 지원을 통해 한달간 무료로 Pluralsight의 강의를 들으실 수도 있습니다.

AND

ARTICLE CATEGORY

분류 전체보기 (56)
Programming (45)
MSDN (4)
개발노트 (2)
reference (5)

RECENT ARTICLE

RECENT COMMENT

CALENDAR

«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

ARCHIVE