윈도우 앱개발을 향하여

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

'.NET'에 해당되는 글 4건

  1. 2018.01.01
    (Localization and Globalization in .NET) Globalization
  2. 2018.01.01
    (Localization and Globalization in .NET) Considerations
  3. 2017.12.30
    (Localization and Globalization in .Net) Fundamentals
  4. 2017.12.03
    .Net ecosystem

Copyright

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



Globalization
The process of engineering an application so that it does not have cultural preconceptions
(Dates, Calendar, Numbers, Currency, etc)


A Good Use of Flags
문화를 대표하면서도 언어를 다르게 설정하기에 좋은 이미지가 바로 국기이다.
e.g., 캐나다 국기와 함께 영어 또는 프랑스어를 사용


IFormatProvider
Use IFormatProvider to ensure the format based on the correct culture

IFormatProvider is an interface and used a lot as Optional parameter of ToString method
CultureInfo class implements IFormatProvider, so We can pass a CultureInfo object to ToString method
e.g., currentDate.ToString("d", new CultureInfo("en-US");
The same method exists in integer.ToString, decimal.ToString, and other classes

DateTime.Parse
We can parse a DateTime like DateTime.Parse("10/23/2015"); OR use DateTime.Parse(string s);
But we should USE DateTime.Parse(string s, IFormatProvider provider);
If we do not provide the IFormatProvider parameter, it uses the CurrentCulture (which may not be what we expect)


Currency Considerations
ToString with a currency format will use the CurrentCulture

The Solution
1. Use a single currency regardless of CurrentCulture (like US dollar)
e.g., 100M.ToString("C", new CultureInfo("en-US"));
2. Incorporate a currency conversion
We can get the conversion factor from a database or store it as a resource
although the resource would need to be updated frequently



Summary (생략)


Course Summary (생략)


Resource

Resgen.exe : Converts between different resource file types (.txt, .resx, .resources, .resw) (link)

LocBaml : Another way to localize WPF applications (link)

Globalization, Internationalization, and Localization in ASP.NET MVC 3, JavaScript and jQuery (link)



출처

이 모든 내용은 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

Copyright

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



Outline

Naming Resource Strings

Danger of culture-specific Image

Translation Considerations

Screen Layout

Exception Messags

Code Analysis Globalization Rule



Resource Naming Recommendation

Name the resources based on their purpose


Page/View-Level Resources

Naming based on purpose

Grouping_Purpose or Grouping_Grouping_Purpose


Assembly-Level Resources

Naming based on purpose

Module_Grouping_Purpose

e.g., MainWindow_Customer_Rating



The Danger of culture-specific Images


The Danger of Flags for Language


If possible, use images that do not rely on culture-specific references

e.g., A US mailbox may not be recognized in another culture, use a letter or postage stamp image instead


If possible, do not include words as part of images


If it is not possible to avoid culture-specific references, then load localized images into the .resx file along with localized strings



Translation Considerations

Machine Translation (like google translator)

Not good enough to go straight into production

But can help with screen layout during development


Human Translation

Prefer native speakers of the target language

Still not perfect - Locker Issue


Best Bet

A human translator who understands the business purpose of the application

Provide the human translator with the business context and let him determine what is best

(Screen shots and Descriptions of a program... etc)



Screen Layout Concerns

Different languages take up different amounts of space.

German words are usually long

Japanese words are usually short

Some languages read right-to-left


Use flow layouts for greatest flexibility

In XAML : use grids and stack panels to hold our controls

Avoid fixed positions and sizes

Favor auto-sizing controls and grids



Windows Forms : TableLayoutPanel, WinRes Tool

WPF, UWP : Grids and StackPanels, Grid - Auto and Star



Exception Messages

To Localize...

The message is displayed to the user

The user can act on the message


To not Localize...

The message is not displayed to the user

The message is logged for support staff



# Exception Thrower

private void ExceptionThrower(Type exceptionType)

{

var currentCulture = Thread.CurrentThread.CurrentUICulutre;

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

try

{

Exception ex;

ex = Activator.CreateInstance(exceptionType) as Exception;

throw ex;

}

finally

{

Thread.CurrentThread.CurrentUICulture = currentCulture;

}

}



Code Analysis Globalization Rule


FXCop is a downloadable tool that analyzes our code and provides suggestions based on a set of rules

This has been incorporated into the Code Analysis tool that is available in some of the VS versions

We're able to choose a rule set that we want to use for analysis in our project.

This is available in the Solution properties.

One of the rule sets is Microsoft Globalization Rules (specifically checks for items that may affect localization and globalization)

The Globalization Rule Set consists of 11 Rules (check the rules for detail)


e.g., 1.Set Microsoft Globalization Rules in Solution properties -> Code Analysis Settings -> Change Rule Set

2. Analyze menu -> Run Code Analysis On Solution

3. Fix the error messages


Warning : Code Analysis do not work at XAML markup




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의 강의를 들으실 수도 있습니다.

'Programming > .NET' 카테고리의 다른 글

(Localization and Globalization in .NET) Globalization  (0) 2018.01.01
(Localization and Globalization in .Net) Fundamentals  (0) 2017.12.30
.Net ecosystem  (0) 2017.12.03
AND

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

Copyright

이 모든 내용은 pluralsight에 있는 Barry Luijbregts가 올린 The .NET Ecosystem: The Big Picture이라는 강의를 듣고 정리한 것입니다(https://app.pluralsight.com/library/courses/dotnet-ecosystem-big-picture/table-of-contents). Barry Luijbregts 원작자께 블로그 게시 허가도 받았습니다.



.Net development platform

includes Runtimes, .Net APIs, Compilers, languages and runtime component




1. Runtimes

런타임들(.NET Framework, .NET Core, Mono)은 모두 application과 library를 만들기위한 frameworks를 포함한다.


1-1 .NET Framework (프레임워크라고 되어있으나 실상은 런타임이고 플랫폼이다.)



Workloads (application type)

 - Console application

 - Windows communication Foundation (old web service communication)

 - Windows Workflow Foundation (Automate business processes)

 - Windows Presentation Foundation (Windows desktop application with potentially complex UIs)

 - Windows Forms ((Windows desktop application with simple UIs)

 - ASP.NET (Web applications)

     - (ASP.NET) Forms, MVC, Web API applications

 - Azure (WebJobs, Cloud Services)

some of them uses specific Windows APIs



.NET Framework provides a lot of functionality through its Class Library

(Classes, interfaces and value types... like string and collections)

.NET Framework Class Library is sometimes called as the Base Class Library. It contains specific functionality for windows platform, like classes to interact with the file system.




CLR = a thing that is part of the common infrastructure of the languages and build tools that all runtimes have.

 - Run code(Compilation mechanism like JIT compilation)

 - Garbage Collection(runtime helper mechanism)

 - C#, VB.NET, F# codes are run and managed by CLR

(CLR also manages communication between managed code and unmanaged code, like when calls API in the windows platform)


특징 : Windows centric (윈도우 전용 API들을 사용하기 때문)

.NET Framework only runs on the Windows platform(Windows Client version like Windows10, Windows Server versions like Windows server 2016)


.NET Framework의 1,2,4 버전을 컴퓨터에 각자 설치가능하고 1버전을 사용하는 application이나 4버전을 사용하는 application이 있을 수 있다. 그러나 4.7 버전을 설치하면 기존의 4.5버전은 사라진다. (즉 메이저 버전을 단위로 끊어진다. == not true side by side) 

- Major version = new CLR (ex) 3.5 -> 4

- Minor version = new library   (ex) 4.5.2 -> 4.6

- Revision = bug fixes (ex) 4.6 -> 4.6.2


.NET Framework는 C:\Windows\Microsoft.NET\Framework에 설치되어있다.




1-2 .NET Core (runtime)

open source(https://github.com/dotnet/core)


Workloads (application type)

 - Console application

 - ASP.NETCore

     - MVC, API

 - UWP (Universal Windows Platform)


.Net Core Class Library contains Classes like collections, file I/O, XML, and async. It's a subset of .NET Framework library to be more streamlined and lightweight. Basis of application to be small as it can be and additional component can be pulled in through Nuget


CoreCLR = part of the common infrastructure, It is different with .NET Framework CLR, CoreCLR is more lightweight and geared towards running code cross-platform and cross-architecture(it runs on x84, x64 and ARM CPU).

 - Assembly loading, Garbage Collection, C#, F#, VB.NET


App Host = usually .NET.exe (allow .NET Core to run on multiple platforms)

This launches .NET Core apps by hosting the CLR and libraries.


Windows Client, Windows Server, Windows IOT (like Raspberry Pi)

Linux (all sort of Linux distributions like Red Hat, Ubuntu, Tizen)

FreeBSD (UNIX like OS)

Mac OS X


.NET Core를 설치하면 선택한 버전의 application host(dotnet.exe)와 CoreCLR, library를 사용할 수 있게 된다. Application들은 원하는 버전의 .NET Core를 사용가능하며 심지어 .NET Core를 기기에 설치하지 않고 application이 자체적으로 필요한 .NET Core를 가지고 있을 수도 있다(self contained application). 보통 컴퓨터에는 C:\Program Files\dotnet에 설치되어있고, shared폴더에 버전들이 있다(각 버전들은 App Host인 dotnet.exe와 class library를 구성하는 많은 API들을 포함하고있다).


.NET Core 프로젝트를 생성해 프로그램을 만든뒤 솔루션을 우클릭하여 publish할 수 있다. dotnet.exe로 실행가능한 프로그램이 된다. self-contained application을 만들기 위해서는 csproj파일에 RuntimeIdentifier를 지정해주어야한다(ex win10-x64;osx.10.12-x64   윈도우10과 맥에서 실행가능하다. 세팅을 통해 윈10과 맥 버전을 따로 다른 폴더에 지정해 publish한다). 그리고 publish하면 library와 dll 그리고 실행가능한 exe까지 함께 만들어진다.




1-3 Mono (runtime) for Xamrin

Mono runtime은 .NET Framework CLR의 cross-platform을 지원한다. open source (http://github.com/mono/mono)

이 글에서는 Mono for Xamrin만 소개한다.



Workloads (type of application)

 - Apple IOS application

 - Apple Mac OS X application

 - Android applications

 - etc


All application workloads packages their application as self-contained application.


Xamarin Class Library is a subset of .NET Framework Class Library


Mono Runtime은 .NET Framework와 거의 동일한 common infrastructure를 가진다(Garbage Collector, JIT). 그러나 Mono Runtime은 C#만 작동하며 AOT(ahead of time compiler)을 추가로 지원한다.    



특징 : Cross platform (This is used to build and run native mobile application across mobile platforms.)

Specific API for IOS, Android, Xamarin.Mac






- 3개의 Runtime 비교




2. .Net Standard Library (purpose == share code between runtimes)

Set of .NET APIs formal specifications that describes APIs and what they do, Not a physical thing to download or install.

Evolution of Portable Class Library(PCL), .NET Standard replace PCL

(ps. PCL은 프로젝트간에 코드를 공유할 수 있는 다른 방법을 제공한다.)

 

All three runtimes implements .Net Standard Library

.Net Standard Library is a specification of .Net APIs that have implementations for each runtime.

때문에 다른 runtime에서 만들어진 코드가 다른 runtime에서도 실행가능하다.

(실전 : .NET Standard Library project를 생성해서 다른 runtime project에서 사용가능하다.)


Specific Runtime versions implements specific versions of .NET Standard, thereby implementing a specific set of APIs. 

(ex. .NET Framework 4.5 implements .NET Standard <= 1.1)


.NET Standard versioning

.NET Standard의 각 버전은 이전 버전의 API들을 포함한다.

( => higher version contains more API, lower version are supported by more platforms, so target the lowest version as possible)

(버전별 API검색 : http://docs.microsoft.com/en-us/dotnet/api)

(VS marketplace에 있는 .NET Portability Analyzer로 현재 프로젝트가 어떤 .NET Standard version과 매칭하는지 확인할 수 있다.)

There is no breaking changes between versions.

Once shipped, versions are frozen



+ Shared project template in VS == just links between files and projects, act as file-sharing mechanism between project 

do not result in assemblies when it built, do not provide APIs

(in compiler's view there is no shared project, shared project is contained inside of other project which referencing it. VS specific functionality)


3. Common Infrastructure


Build Tools (compiler like Roslyn, CLR, CoreCLR...)

Languages (C#, F#, VB.NET...)

Runtime Components (Garbage Collection, JIT...)


 - The .Net Framework Toolchain

(The purpose of the toolchain is to turn code into a running application)


MSBuild(build engine provided by MS. sln, .csproj, vbproj...) is a linking pin. MSBuild는 C#, VB.NET code는 Roslyn(.NET Compiler Platform)을, F# code에게는 F# Compiler를 호출한다. 결과는 exe, dll같은 IL이다. Intermediate Language(IL)은 CLR과 같은 runtime에 의해 해석된다.


Common Language Runtime(CLR)은 JIT(just-in-time) compiler를 가지고 있으며, 이 컴파일러로 IL을 해당 OS가 이해할 수 있는 native code로 컴파일한다.

CLR also acts as a host for running the application. Native code lives in memory and is managed by the CLR. It has tools for that like the garbage collector.


이 모든 과정을 개발자가 직접 할 수도 있으나 대부분의 경우 이런 일들은 VS와 같은 도구(MSBuild를 실행하는)가 해결한다.



- The .NET Core Toolchain

MSBuild는 .NET Core에서도 사용되며 IL이 나오기까지의 과정은 .NET Framework와 동일하다.


Core Common Language Runtime(CoreCLR)이 IL을 사용한다. CoreCLR은 .NET Framework CLR과 다르다. 가장 큰 차이점은 CoreCLR은 multiple platform(Mac OS나 Linux 등)에서 실행가능하다는 점이다. CoreCLR도 JIT compiler를 포함하고 있으며 IL을 Window, Mac OS, Linux등의 OS가 사용가능한 Native code로 컴파일한다. 이것은 ASP.NET Core나 콘솔 application의 경우이고 UWP는 조금 다른 경로로 Native code를 생성한다.


UWP app is compiled ahead of time with an ahead-of-time compiler(AOT compiler). 이런 방식을 .NET Native라 부른다.

AOT compiler compiles IL code into native code, but it produce this code as a deployable package instead of compiling the code on demand at runtime. This provide performance benefit.


Just like in the .NET Framework native code is run by the CoreCLR which provide capability like garbage collection.


그러나 .NET Framework CLR과 달리 CoreCLR과 Native Code는 application host process에 의해 load되고 kicked off된다. This process(dotnet.exe) hosts the CoreCLR and makes it run native code. 



- The Mono for Xamrin Toolchain

MSBuild가 조정자로써 동일하게 사용되나 앞전 2개와 달리 C#으로 작성된 프로젝트와 코드만 지원한다. (.sln, csproj)


C# code for Android compiled to IL by Xamarin Compiler. Then Mono Runtime's JIT compiler compiles it to Native code(specific for that android device on demand at runtime). 또한 Mono Runtime은 garbage collection과 같은 runtime service를 제공한다.


C# code for iOS의 경우 Xamarin Compiler가 모든 코드를 C# compiler나 AOT compiler를 이용해 native code로 precompile한다. This is special process that produces a package specifically for iOS containing its native code, which is ARM assembly language. iOS understand this and can run it.





- Summary of Toolchain





4. What to use When? (생략)


Copyright

이 모든 내용은 pluralsight에 있는 Barry Luijbregts라는 분이 올린 The .NET Ecosystem: The Big Picture이라는 강의를 듣고 정리한 것입니다. (https://app.pluralsight.com/library/courses/dotnet-ecosystem-big-picture/table-of-contents)(https://www.azurebarry.com/dot-net-ecosystem-explained) 강의에선 더 자세한 설명과 Demo를 포함하고 있으며, 마지막 What to use When?에 대한 내용 정리는 생략하겠습니다. Pluralsight에서 확인하세요. Microsoft 계정으로 한달간 무료로 Pluralsight의 수많은 강의를 시청하실 수도 있습니다.

AND

ARTICLE CATEGORY

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

RECENT ARTICLE

RECENT COMMENT

CALENDAR

«   2024/04   »
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

ARCHIVE