Developing WorldReady Applications for Windows 2000XP - PowerPoint PPT Presentation

1 / 77
About This Presentation
Title:

Developing WorldReady Applications for Windows 2000XP

Description:

Response.Write( FormatDateTime(dtNow) ) % Locale awareness in .NET. Class: System.Globalization ... reordering (Arabic, Hebrew) Contextual shaping (Arabic, ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 78
Provided by: downloadM
Category:

less

Transcript and Presenter's Notes

Title: Developing WorldReady Applications for Windows 2000XP


1
Developing World-Ready Applications for Windows
2000/XP
Houman Pournasseh Lead Program Manager Russ
Rolfe Program Manager Windows Division
2
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

3
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

4
Definitions
  • World-Ready Properly globalized and
    localizable.
  • Globalization The process of designing and
    implementing source code so that it can
    accommodate any local market (locale) or
    script.
  • Localizability Designing software code and
    resources such that resources can be localized
    for any local market (locale) without changing
    the source code.
  • Localization The process of adapting a product
    (including both text and non-text elements) to
    meet the language, cultural, and political
    expectations and/or requirements of a specific
    local market (locale).

5
Users and Locales
To define formatting for date, time,users set
the user locale
6
Windows XP International Enhancements
  • Nine (9) new locales added to previous list of
    126.
  • Punjabi, Gujarati, Telugu, Kannada, Kyrgyz,
    Mongolian (Cyrillic), Galician, Divehi, Syriac
  • Over 10 new languages and scripts,
  • More robust font display for East Asian
    languages.
  • Improved Regional Settings options.
  • Largely improved MUI support
  • New location (GEO)

7
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

8
Why invest in World Ready products?
  • Get into international market (World Wide Web
    era)
  • Create a single functionality binary to
  • Reduce development effort and cost
  • Ease support and maintenance pain

9
Why invest in World Ready products?
  • Sim-Ship all language versions at once saves lost
    revenue.

Release Eng Ver 1.0
Release Eng Ver 1.1
Release Ger Ver 1.0
Release Ger Ver 1.1
10
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

11
Windows 2000/XP Unicode Single Binary
  • Built in support for hundreds of languages
  • Any (well behaved) language Win32 application can
    run on any language version of Windows 2000/XP
  • Native Unicode support for new scripts
  • Surrogate support

12
Unicode Encoding
  • Non-Unicode applications behavior depends on
    users settings and makes data exchange between
    OS language versions impossible.

13
Legacy systems support
  • Few exceptions for not Fully Unicode apps
  • App has to run on Win9x and NT
  • Existing Internet protocols and standards require
    special encoding
  • Supporting apps that need to run on Win9x
  • Create two separate binaries one ANSI one
    Unicode
  • Register as ANSI and internally convert to/from
    Unicode as needed
  • Use MSLU!

14
Data types
  • For 8 bit and double-byte characters
  • typedef char CHAR // 8 bit character
  • typedef char LPSTR // pointer to 8 bit string
  • For Unicode (Wide) characters
  • typedef unsigned short WCHAR // 16 bit character
  • typedef WCHAR LPWSTR //pointer to 16 bit string

TCHAR
LPTSTR
wchar_t
char
wchar_t
char
15
Win32 API prototypes
  • Generic function prototypes// winuser.hifdef
    UNICODEdefine SetWindowText
    SetWindowTextWelsedefine SetWindowText
    SetWindowTextAendif // UNICODE
  • A routines behavior under Windows 2000/XP
  • W routines behavior under Win9x

16
C run time extensions
Compile with D_UNICODE to get Unicode version
Compile with DUNICODE to get Unicode version
17
Unicode ? ANSI
  • Converting between ANSI and Unicode
  • MultiByteToWideChar for codepage ? Unicode
  • WideCharToMultiByte for Unicode ? codepage
  • CP can be any legal codepage number or a
    predefined such as CP_ACP, CP_SYMBOL, CP_UTF8,
    etc.
  • Tips for writing Unicode
  • Use generic data types and function prototypes
  • Replace p/p-- with CharNext/CharPrev
  • Compute buffer sizes in TCHAR

18
Quiz
  • What is the size (in bytes) of a text file saved
    as Unicode in Notepad which contains hello
  • 5
  • 12
  • 10
  • 20

19
Quiz
  • What is the size (in bytes) of a text file saved
    as Unicode in Notepad which contains hello
  • 5
  • 12
  • 10
  • 20

20
Quiz
  • Which one of the following APIs is not defined in
    Windows 2000 / Windows XP?
  • SetWindowTextW
  • SetWindowTextA
  • SetWindowPosW
  • SetWindowPos

21
Quiz
  • Which one of the following APIs is not defined in
    Windows 2000 / Windows XP?
  • SetWindowTextW
  • SetWindowTextA
  • SetWindowPosW
  • SetWindowPos

22
Demo!
Porting an ANSI application to Unicode
23
Encodings in Web pages
  • ANSI codepages or ISO character encodings
  • Mono-lingual or restricted to one script
  • Raw Unicode UTF-16
  • OK for Windows NT networks
  • Number entities 2325
  • OK for occasional use
  • UTF-8 Recommended encoding
  • Supported by IE 4.0 and Netscape 4.0

24
Setting web encoding
  • HTML/DHTML
  • Tag in the head of the document
  • ltMETA HTTP-EQUIV"Content-Type"
    CONTENT"text/html charsetltvaluegt"gt
  • XML
  • lt?xml version1.0 encodingltvaluegt?gt
  • ASP
  • Specify charset using ASP directives
  • Per session
  • ltSession.CodePageltcharsetgtgt
  • Per page
  • lt_at_CODEPAGEltcharsetgtgt

25
Setting encodings for .NET
  • Class System.Text
  • Distinction between File, Request, and Response
    encodings
  • in code
  • Response.ContentEncodingltvaluegt
  • in page directive
  • lt_at_Page ResponseEncodingltvaluegtgt
  • in configuration file
  • ltglobalization
  • requestEncodingltvaluegt
  • responseEncodingltvaluegt
  • fileEncodingltvaluegt /gt

26
Universally encoded page
27
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

28
Quiz
  • In Gregorian calendar, what date is represented
    by 07/04/01?
  • July 4, 2001
  • April 7, 2001
  • April 1st, 2001
  • Depends on where I am!

29
Quiz
  • In Gregorian calendar, what date is represented
    by 07/04/01?
  • July 4, 2001
  • April 7, 2001
  • April 1st, 2001
  • Depends on where I am!

30
Windows 2000/XP National Language Settings
  • NLS APIs allow you to automatically adjust to
    users formatting preferences
  • Date 07/04/01 is ?? 13?7?4? in Japan
  • Time 900PM is 2100 in the France
  • Currency 1,000.00 is 1.000,00 in Germany
  • Large Numbers 123,456,789.00 is
    12,34,56,789.00 in Hindi
  • Sort Order German ä comes after a
    Swedish ä comes after z

31
Locale awareness
  • Eliminate implicit locale assumptions from code
  • define ToUpper(ch) \
  • ((ch)lt'Z' ? (ch) (ch)'A' - 'a')
  • Query system to format locale-dependent data
    using NLS APIs and LCIDs.

32
NLS APIs Getting and setting locales
  • Querying locales
  • LCID GetSystemDefaultLCID
  • EnumSystemLocales
  • LCID GetUserDefaultLCID()
  • LCID GetThreadLocale()
  • Setting locales
  • BOOL SetThreadLocale(LCID dwNewLocale)
  • BOOL SetLocaleInfo(LCID,)// Works for standard
    locales only!
  • No APIs to set System locale, User locale, and UI
    language

33
NLS APIs Querying locale information
  • To retrieve information specific to a given
    locale GetLocaleInfo
  • Gives information for any valid locale (takes an
    LCID).
  • LCTYPE input tells type of info to retrieve for a
    given locale (e.g. currency symbol, name of
    months).
  • Returns info in string buffer (LPTSTR).
  • To retrieve information specific to a location
    GetGeoInfo
  • Gives information for any valid location (takes
    an LCID).
  • SYSGEOTYPE input tells type of info to retrieve
    for a given location(e.g. LCID, Time zones).

34
NLS APIs Formatting data
  • To enumerate formats
  • EnumCalendarInfo(Ex)
  • EnumDateFormats
  • EnumTimeFormats
  • To format data directly
  • GetCurrencyFormat
  • GetDateFormat
  • GetTimeFormat

35
Demo!
A locale aware application
36
Locale awareness in web pages
  • To retrieve user locale
  • A server variable
  • Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")
  • A property of the navigator object
  • navigator.UserLanguage
  • To set a locale
  • In DHTML
  • SetLocale("de")
  • DateData FormatDateTime(now(), vbShortDate)
  • In ASP
  • lt Session.LCID 1041 gt
  • lt Response.Write( FormatDateTime(dtNow) ) gt

37
Locale awareness in .NET
  • Class System.Globalization
  • Referenced as CultureInfo set of preferences
    based on language and culture.
  • Pattern xx-XX, such as fr-CA, de-AT (RFC-1766)
  • Setting the CultureInfo
  • Implicit Picked up from User Locale
  • Explicit
  • In code Thread.CurrentThread.CurrentCulture
    new CultureInfo (de-DE)
  • In page directive lt_at_Page Cultureltvaluegtgt
  • In config ltglobalization cultureltvaluegt /gt

38
Demo!
Locale aware web site
39
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

40
Handling Input methods
  • Easiest Using edit controls (recommended)
  • Responding directly to user input
  • Input locales (language input method) HKL
  • GetKeyboardLayout
  • ActivateKeyboardLayout
  • LoadKeyboardLayout
  • Windows messages
  • WM_INPUTLANGCHANGEREQUEST
  • WM_INPUTLANGCHANGE
  • WM_IME. (for IME support only)
  • WM_CHAR and WM_IME_CHAR

41
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

42
Windows 2000/XP Complex Scripts
  • Complex Scripts have one or more of the following
    attributes
  • Bi-directional (BiDi) reordering (Arabic, Hebrew)
  • Contextual shaping (Arabic, Indic family)
  • Display of combining characters (Arabic, Thai,
    Indic)
  • Specialized word-breaking (Thai)
  • Avoid illegal character combinations (Thai,
    Indic)
  • Text Justification (Arabic)

43
Complex Scripts BiDi reordering
Back
44
Complex Scripts Contextual Shaping
Back
45
Complex Scripts Combining Characters
Back
46
Complex Scripts Justification
Back
47
Uniscribe
  • Clients Windows 2000/XP, Trident, Microsoft
    Office 2000/XP
  • A collection of exported APIs (high and low
    level)
  • Hides implementation details
  • A shaping engine per language

Application
LPK.DLL
USERGDI
USP
48
Options to display text
  • Plain text in application
  • Standard edit control or
  • Win32 API (ExtTextOut / DrawText).
  • Simple formatted text
  • In Win32 apps, use Richedit control.
  • For Web pages, use Document Object Model (DHTML).
  • Advanced formatting
  • Use Uniscribe (see SDK and MSJ article).

49
Special considerations
  • When dealing with BiDi, set RTL reading order and
    alignment
  • SetTextAlign / GetTextAlign with TA_RIGHT
  • ExtTextOut with ETO_RTLREADING
  • DrawText with DT_RTLREADING
  • To measure line lengths
  • Do not sum cached character widths
  • Do use a GetTextExtent function or Uniscribe
  • When displaying typed text
  • Do not output characters one at a time!
  • Do save text in a buffer and display the whole
    string with Uniscribe or Win32 API

50
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

51
Windows 2000/XP Font support
  • Introduction of OpenType fonts
  • Extended TTF with glyphs for PE, ME, Thai, Greek,
    Turkish, Cyrillic
  • Font fallback mechanism for CS and Eastern Asian
    scripts used by Uniscribe
  • Font linking mechanism used by GDI

52
Font independency Win32 programming
  • Not to do
  • Hard code font face names
  • Assume a given font is installed
  • Assume selected font supports the desired script
  • To do
  • Use MS Shell Dlg face name in Dialog resources
  • EnumFontFamiliesEx or ChooseFont to select fonts

53
Font independency In Web pages
  • Avoid placing text formatting values into in-line
    style.
  • ltspan style "font-size 10pt font-family
    Arial"gt Hello lt/spangt
  • Declare text style in CSS files
  • ltstylegt
  • .myStyle font-size 10pt font-family
    Arial
  • lt/stylegt
  • ltspan class myStylegt Hello lt/spangt
  • Use WEFT to embed fonts to your web pages (IE
    only)
  • http//www.microsoft.com/typography/web/default.ht
    m

54
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

55
Windows 2000/XP Multilanguage UI
  • Multilanguage version of Windows 2000/XP allows
    you to
  • Switch the language of UI without rebooting
  • Set the language of UI per user
  • Add/Remove language modules
  • Offer your own solution for a multilingual UI

56
Multilingual UI Applications Possible options
  • One localized .exe per target language
  • One multilingual language resource DLL
  • One resource DLL per target language

57
Satellite DLL
  • Initialize to current UI language.
  • Windows 2000/XP GetUserDefaultUILanguage()
  • Down-level platforms See Writing Multilingual
    User Interface Applications on Globaldev.
  • Allow user to select UI language.
  • Use naming convention, for example
    resltLANGIDgt.dll
  • Find all resource DLLs using FindFirstFile and
    FindNextFile
  • Use LoadLibrary(Ex) to load DLL file

58
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

59
Windows 2000/XP Mirroring technology
To create an automatic right-to-left layout of
the user interface for localized versions of
bidirectional languages (Arabic and Hebrew).
60
Coordinate transformation
  • Origin (0,0) in upper RIGHT corner of window
  • X scale factor -1
  • X values increase from right to left

Origin
Origin
Increasing x
Increasing x
0
1
0
1
Default (LTR) window
Mirrored (RTL) window
61
Controlling the mirroring style
  • Per Process
  • GetProcessDefaultLayout
  • SetProcessDefaultLayout (LAYOUT_RTL)
  • Per window
  • CreateWindowEx (WS_EX_LAYOUTRTL
    WS_EX_NOINHERITLAYOUT )
  • SetWindowLong
  • Per DC
  • GetLayout / SetLayout
  • LAYOUT_BITMAPORIENTATIONPRESERVED

62
Controlling the mirroring style
  • Dialog Resources
  • Set WS_EX_LAYOUTRTL in dialog template
  • Message boxes
  • Use MB_RTLLAYOUT option
  • BitBlt/StretchBlt
  • Use NOMIRRORBITMAP flag

63
Mirroring common issues
  • Mirrored bitmap!

Off screen bitblt
64
BiDi mirroring in web pages
  • In a web context, mirroring and RTL reading order
    go hand-in-hand
  • Using DIR attribute would
  • Set the right alignment of the text
  • Set the right_to_left reading order of the text
  • Mirror the page context
  • Leave the orientation of stationary elements
  • To set DIR attribute
  • Html lthtml dirRTLgt
  • At an element level ltspan dir RTLgt
  • DHTML object document.Dir "RTL

65
Tips for BiDi web pages
  • Directional images
  • ltIMG stylefilterflipH SRCarrow.jpg gt
  • Avoid explicit alignments
  • Obsolete usage of alignleft in tables and
    cells
  • Avoid absolute positioning of elements
  • Remember tables get mirrored automatically, use
    them for robust reversibility!

66
Demo!
Mirrored DHTML
67
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

68
Localizability
  • Localization of software Adapting user interface
    elements to a specific language
  • Should require no engineering changes!
  • Changes to code are part of localizability
    process
  • Source code changes, due to localization, are
    bugs in the core code!

69
Challenges
  • Developers are focused on their primary language
  • Coding tricks to save work (saves a few )
  • Hardcoded strings
  • Creating text strings from phrases by
    concatenation
  • Creates dialog boxes using overlapped controls
  • The tricks cost lots of because
  • Bugs difficult to detect before localization is
    done
  • Code change required to address the issue

70
Unbreakable rules (1/3)
  • Remove all localizable resources from source
    code, place in standard resource file
  • Do not place non-localizable strings in resource
    file

71
Unbreakable rules (2/3)
  • Avoid composite strings that are built at
    runtime
  • Wrong way
  • var t1_text "Not enough memory to"
  • t2_text "the file"
  • v1_text "open"
  • v2_text "copy"
  • v3_text "save"
  • ...
  • text t1_text" "v2_text" "t2_text"
    "filename"."
  • Right way
  • var t1_text "Not enough memory to open the file
    s1."
  • var t2_text "Not enough memory to copy the file
    s1."
  • var t3_text "Not enough memory to save the file
    s1."
  • Use FormatMessage for multiple variable sentences
  • Thus "Not enough memory to s1 the file s2."
  • Becomes Liian vähän muistia tiedoston 2 1.

72
Unbreakable rules (3/3)
  • Do not reuse string resources
  • If the same string resource is to be used in more
    than one place, create one instance of the
    resource per use
  • Use the same resource identifiers throughout the
    life of a product

73
Text Expansion
  • Allow for text expansion

  • Rule of thumb
  • lt 10 300
  • gt 10 30

74
Text Expansion (web pages)
  • Design so Entire Dialog Consists of Tables
  • ltbodygtlt!-- Use one main table --gtlttable
    width100gtlt can contain other tables
    gtlt/tablegt
  • lt/bodygt
  • Avoid Fixed Width Items
  • Each Control Should be in a Separate Cell
  • Allow Text Wrapping - do not use nowrap
  • Separate Check Boxes and Radio Buttons from Labels

75
Text Expansion HTML Dialogs
76
Mirroring HTML Dialogs
77
Localizability
  • Pseudo-Localization is a good way to test
    Localizability

78
Agenda
  • Definitions
  • Why invest in World-Ready products?
  • Globalization step-by-step
  • Universal encoding - Unicode
  • Locale aware
  • Handle different input methods
  • Complex script aware
  • Font independency
  • Multi-lingual UI aware
  • Mirroring aware
  • Localizability
  • Conclusion References

79
Final Conclusions
  • Benefits of investing in development of
    World-Ready applications are real
  • Windows 2000/XP eases the pain and sets the
    standard
  • The biggest task in implementing World-Ready
    applications is setting the designers and
    engineers mind-set to think GLOBAL

80
Resources
  • MSDN for latest documentation about new APIs
  • Developing International Software for Windows 95
    and Windows NT
  • Windows 2000/XP Globalization http//www.microso
    ft.com/globaldev
  • World-Ready Guide
  • You are not World-Ready If
  • E-Mail aliases drintl_at_microsoft.com gdhelp_at_micr
    osoft.com

81
Questions?
Write a Comment
User Comments (0)
About PowerShow.com