CS 174: Web Programming November 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
CS 174: Web Programming April 28 Class Meeting
Advertisements

©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. COMPSCI 125 Introduction to Computer Science I.
Internationalization of Java Platform Presenter: Ataru Nakazawa Advisor: Xiaoping Jia Date: January 23, 2004.
CS 185C: The History of Computing August 24 Class Meeting Department of Computer Science San Jose State University Fall 2011 Instructor: Ron Mak
CS 235: User Interface Design January 22 Class Meeting
CS 174: Web Programming February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 146: Data Structures and Algorithms July 14 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Digital/physical content store. Summary Create a digital content/physical product web store based on osCommerce. Following items can be sold in the store:
CS 151: Object-Oriented Design December 5 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 235: User Interface Design April 7 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Sophia Antipolis, September 2006 Multilinguality, localization and internationalization Miruna Bădescu Finsiel Romania.
CS 157B: Database Management Systems II March 18 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
CS 149: Operating Systems May 7 Class Meeting
Practical PHP IDIA Spring 2012 Bridget M. Blodgett.
CS 152: Programming Language Paradigms April 9 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
Sakai: Localization & Internationalization Beth Kirschner University of Michigan
CS 149: Operating Systems January 22 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 235: User Interface Design November 3 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Company Confidential 1 This presentation is solely for the use of Patni personnel. No part of it may be circulated, quoted, or reproduced for distribution.
CS 235: User Interface Design October 15 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 157B: Database Management Systems II March 20 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 26 Internationalization.
Chapter 12: Internationalization Processing Date and Time Processing Date and Time  Locale  Date  TimeZone  Calendar and GregorianCalendar  DateFormat.
CS 174: Web Programming September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 235: User Interface Design September 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
CS 149: Operating Systems April 7 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Reports and Learning Resources Module 5 1. SLMS Primary Administrator Training Module 5: Reports and Learning Resources 2.
CS 151: Object-Oriented Design September 5 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak
CS 151: Object-Oriented Design September 12 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
Chapter 14 Internationalization F Processing Date and Time –Locale –Date –TimeZone –Calendar and GregorianCalendar –DateFormat and SimpleDateFormat F Formatting.
Week 7 Lecture 2 Globalization Support in the Database.
CS 174: Web Programming September 28 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 146: Data Structures and Algorithms July 14 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
1 CS1430: Programming in C++ Section 2 Instructor: Qi Yang 213 Ullrich
CS 174: Web Programming October 14 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CMPE 226 Database Systems November 18 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
CMPE 226 Database Systems October 28 Class Meeting
CS 160: Software Engineering December 10 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
1 Chapter 20 Internationalization. 2 Objectives F To describe Java's internationalization features (§ 20.1). F To construct a locale with language, country,
CS 153: Concepts of Compiler Design November 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 152: Programming Language Paradigms April 30 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
CS 153: Concepts of Compiler Design November 18 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 151: Object-Oriented Design October 29 Class Meeting Department of Computer Science San Jose State University Fall 2013 Instructor: Ron Mak
CS 174: Web Programming November 2 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 235: User Interface Design April 28 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Systems Software. Systems software Applications software such as word processing, spreadsheet or graphics packages Operating systems software to control.
CS 154 Formal Languages and Computability April 12 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability April 19 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 160 and CMPE/SE 131 Software Engineering May 12 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CS 154 Formal Languages and Computability May 12 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability April 5 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 160 and CMPE/SE 131 Software Engineering April 19 Class Meeting Department of Computer Science Department of Computer Engineering San José State University.
CMPE 280 Web UI Design and Development August 29 Class Meeting
Chapter 14 Internationalization
CMPE 135: Object-Oriented Analysis and Design November 21 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor:
CMPE Database Systems Exercise #1 Solutions
CMPE 135: Object-Oriented Analysis and Design December 6 Class Meeting
CMPE 135: Object-Oriented Analysis and Design November 29 Class Meeting Department of Computer Engineering San Jose State University Fall 2018 Instructor:
CMPE 152: Compiler Design December 6 Class Meeting
CMPE Database Systems Exercise #3 Solutions
CMPE 152: Compiler Design November 29 Class Meeting
CMPE 135: Object-Oriented Analysis and Design November 29 Class Meeting Department of Computer Engineering San Jose State University Fall 2018 Instructor:
Chapter 35 Internationalization
CMPE/SE 131 Software Engineering May 9 Class Meeting
CMPE 135: Object-Oriented Analysis and Design March 14 Class Meeting
CS 144 Advanced C++ Programming April 25 Class Meeting
CMPE 152: Compiler Design April 25 Class Meeting
CMPE 152: Compiler Design May 2 Class Meeting
CS/SE 157B Database Management Systems II April 24 Class Meeting
Presentation transcript:

CS 174: Web Programming November 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak 2 Unofficial Field Trip  Computer History Museum in Mt. View Provide your own transportation to the museum.  Saturday, November 21, 11:30 – closing time Special free admission. Do a self-guided tour of the Revolution exhibit. See a life-size working model of Charles Babbage’s Difference Engine in operation, a hand-cranked mechanical computer designed in the early 1800s. Experience a fully restored IBM 1401 mainframe computer from the early 1960s in operation.

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak 3 Unofficial Field Trip, cont’d  See the extensive Revolution exhibits! Walk through a timeline of the First 2000 Years of Computing History. Historic computer systems, data processing equipment, and other artifacts. Small theater presentations. Atanasoff-Berry Computer Hollerith Census Machine

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak 4 Unofficial Field Trip, cont’d  Babbage Difference Engine, fully operational Hand-cranked mechanical computer. Computed polynomial functions. Designed by Charles Babbage in the early to mid 1800s.  Arguably the world’s first computer scientist, lived He wasn’t able to build it because he lost his funding.  Live demo at 1:30  His plans survived and this working model was built. Includes a working printer!

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak 5 Unofficial Field Trip, cont’d  IBM 1401 computer, fully restored and operational. A small transistor-based mainframe computer. Extremely popular with small businesses in the late 1950s through the mid 1960s  Maximum of 16K bytes of memory.  800 card/minute card reader (wire brushes).  600 line/minute line printer (impact).  6 magnetic tape drives, no disk drives.

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Unofficial Field Trip, cont’d  Information on the IBM 1401: General info: My summer seminar: Restoration: thelen.org/1401Project/1401RestorationPage.htmlhttp://ed- thelen.org/1401Project/1401RestorationPage.html 6

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak 7 Unofficial Field Trip, cont’d  There will be extra credit if you participate in the visit to the Computer History Museum.  Complete a Canvas quiz. Acceptable answers are to be found among the museum exhibits and presentations. Each correct answer adds one point to your midterm score.

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Internationalization and Localization  Internationalization (I18N) makes an application usable in multiple locales.  Localization (L10N) adds support for a particular locale to an internationalized application.  A locale consists of settings that describe text formatting and language conventions in a particular area of the world.  It’s more than just language translation! 8

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Locale Settings  What language for messages English, French, German, Spanish, Chinese, etc.  How to format dates and times Order of month, day, year Names of the months and of the days of the week 12-hour or 24-hour clock  How to format numbers Currency symbol Group separator, decimal point, negative indicator  How to sort text (collation sequence) 9

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Developing Apps for I18N  Adapt to a user’s locale.  Dynamically determine: What language to display all text, such as labels and messages What format to display numbers, dates, and times How to sort text 10

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak PHP Support for I18N  The intl extension is bundled with PHP versions and later.  If necessary, download from Mac users should see also nstalling-intl-package-on-osx-lion nstalling-intl-package-on-osx-lion Windows users should see also extension-installing-php-intl-dll extension-installing-php-intl-dll 11

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Locale ID  A locale ID has several parts separated by underscores. Two-letter language code as determined by the ISO standard: 1_codes 1_codes Optional country code as determed by the ISO 3166 standard:  Examples: en_US : American English en_GB : British English 12

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Determine a User’s Locale  Determine a user’s locale in order to dynamically localize your web application. Do that on the server with PHP code. 13 <?php if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { $localeToUse = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); } else { $localeToUse = Locale::getDefault(); } print $localeToUse; ?> i18n/locale.php

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Text Messages  Pass the chosen word or phrase to a MessageFormatter object for formatting.  First parameter: the locale to use.  Second parameter: the string to format. 14

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Text Messages, cont’d 15 <?php $template = "{0, spellout}"; $locales = array('en_GB', 'fr_FR', 'de_DE', 'zh_CN'); print " \n"; foreach ($locales as $locale) { print " $locale \n"; } print " \n"; i18n/counter.php

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Text Messages, cont’d 16 for ($i = 0; $i <= 21; $i++) { print " \n"; print " $i \n"; foreach ($locales as $locale) { $msgMF = new MessageFormatter($locale, $template); $msg = $msgMF->format(array($i)); print " $msg \n"; } print " \n"; } print " \n"; ?> i18n/counter.php

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Text Messages, cont’d 17 Output:

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Text Messages, cont’d  The constructor of class MessageFormatter takes two parameters: the locale the string to format  The string can contain ICU parameters. ICU = International Components for Unicode Example: {0, spellout} See project.org/formatparse/messageshttp://userguide.icu- project.org/formatparse/messages 18

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Text Messages, cont’d  Maintain a message catalog of words and phrases in the different languages.  Retrieve the appropriate word or phrase.  Pass the chosen word or phrase to a MessageFormatter object for formatting. 19

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Text Messages, cont’d 20 $messages = array(); $messages['en_US'] = array('FAVORITE' => 'favorite', 'FRIES' => 'french fries', 'CANDY' => 'candy', 'CHIPS' => 'potato chips', 'EGGPLANT' => 'eggplant'); $messages['en_GB'] = array('FAVORITE' => 'favourite', 'FRIES' => 'chips', 'CANDY' => 'sweets', 'CHIPS' => 'crisps', 'EGGPLANT' => 'aubergine'); $locales = array('en_US', 'en_GB'); $sentence = 'My {0} food is {1}.’; i18n/text1.php

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Text Messages, cont’d 21 $favoriteMF = new MessageFormatter($locale, $messages[$locale]['FAVORITE']); $favorite = $favoriteMF->format(array()); $candyMF = new MessageFormatter($locale, $messages[$locale]['CANDY']); $candy = $candyMF->format(array()); $sentenceMF = new MessageFormatter($locale, $sentence); $text = $sentenceMF->format(array($favorite, $candy)); i18n/text1.php Output:

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Dates and Times  Use a MessageFormatter object. Use a date or time argument type. Optionally specify short, medium, or long style. 22 date_default_timezone_set('America/Los_Angeles'); $when = new DateTime(); $message = "It is {0,time,short} on {0,date,medium}."; $fmt = new MessageFormatter('en_US', $message); print $fmt->format(array($when)). "\n"; i18n/dates1.php It is 4:25 AM on Apr 23, Output:

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Dates and Times, cont’d  Use an IntlDateFormatter object to specify the individual parts of a date or time. 23

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Dates and Times, cont’d 24 date_default_timezone_set('America/Los_Angeles'); $fmt = new IntlDateFormatter('en_US', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'America/Los_Angeles'); $when = new DateTime(); $parts = array('tm_sec' => 56, 'tm_min' => 34, 'tm_hour' => 12, 'tm_mday' => 23, 'tm_mon' => 3, /* 0 = January */ 'tm_year' => 115); /* 0 = 1900 */ print $fmt->format($when). " \n"; print $fmt->format($parts); Sunday, November 15, :23:50 PM Pacific Standard Time Thursday, April 23, :34:56 PM Pacific Daylight Time Output: i18n/dates2.php Date type Time type

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Dates and Times, cont’d  IntlDateFormatter::formatObject() helper method. 25 date_default_timezone_set('America/Los_Angeles'); $when = new DateTime('now', new DateTimeZone('America/Los_Angeles')); print IntlDateFormatter::formatObject($when, 'eeee dd MMMM y', 'es_ES'). " \n"; print IntlDateFormatter::formatObject($when, IntlDateFormatter::FULL, 'fr_FR'). " \n"; $formats = array(IntlDateFormatter::FULL, IntlDateFormatter::SHORT); print IntlDateFormatter::formatObject($when, $formats, 'de_DE'); Output: domingo 15 noviembre 2015 dimanche 15 novembre :33:17 heure normale du Pacifique Sonntag, 15. November :33 i18n/dates3.php

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Example Date and Time Formatting Codes 26 TypeCharacterDescriptionExample hour h 12-hour clock (1-12) 7 hour H 24 hour clock (0-23) 18 minute m minute (0-59) 22 second s second (0-59) 49 day d 12 day EEEE day of week (name) Friday month MMMM month name April year y year (4 digits) 2015 other G era (BC or AD) AD

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Numbers  Use a MessageFormatter object to format numbers according to a locale. 27 $x = 5327; $y = 98; $message = '{0,number}/{1,number} = {2,number}'; $args = array($x, $y, $x/$y); $us = new MessageFormatter('en_US',$message); $fr = new MessageFormatter('fr_FR',$message); print $us->format($args). " \n"; print $fr->format($args); Output: 5,327/98 = /98 = 54,357 i18n/numbers.php

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Currency  Use a MessageFormatter object to format currency according to a locale. 28 $income = ; $debit = ; $fmt = new MessageFormatter('en_US', '{0,number,currency} in and '. '{1,number,currency} out'); print $fmt->format(array($income,$debit)); $5, in and ($25.95) out Output: i18n/currency1.php

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Currency, cont’d  Use a NumberFormatter object for more specific formatting of currency. 29 $income = ; $debit = ; $fmt = new NumberFormatter('en_US', NumberFormatter::CURRENCY); print $fmt->formatCurrency($income, 'USD'). ' in and '. $fmt->formatCurrency($debit, 'EUR'). " out"; $5, in and (€25.95) out Output: i18n/currency2.php ISO 4217 currency codes:

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Localize Currency, cont’d 30 $amounts = array(array(152.9, 'USD'), array(328, 'ISK'), array(-100, 'JPY'), array(500.53, 'EUR'), ); $fmt = new NumberFormatter('en_US', NumberFormatter::CURRENCY); $fmt->setAttribute(NumberFormatter::PADDING_POSITION, NumberFormatter::PAD_AFTER_PREFIX); $fmt->setAttribute(NumberFormatter::FORMAT_WIDTH, 15); $fmt->setTextAttribute(NumberFormatter::PADDING_CHARACTER, ' '); foreach ($amounts as $amount) { print $fmt->formatCurrency($amount[0], $amount[1]). " \n"; } $ Ikr 328 (¥ 100) € Output: i18n/currency3.php

Computer Science Dept. Fall 2015: November 16 CS 174: Web Programming © R. Mak Locale-Aware Sorting  Use a Collator object to sort text according to the collating sequence of a locale. 31 $words = array('Малина', 'Клубника', 'Огурец'); $collator = new Collator('ru_RU'); $collator->sort($words); foreach ($words as $word) { print $word. " \n"; } i18n/sorting.php Клубника Малина Огурец Output: