I18n - DateTime ASP.NET MVC. I18n DateTime – EF changes  In model classes, use attributes  DataType(DataType.DateTime)  DataType(DataType.Date)  DataType(DataType.Time)

Slides:



Advertisements
Similar presentations
Macromedia Dreamweaver 4 Foundation Level Course.
Advertisements

The Future of Web WakeUpAndCode.com.
ASP Tutorial. What is ASP? ASP (Active Server Pages) is a Microsoft technology that enables you to make dynamic and interactive web pages. –ASP usually.
ICS 665 Jesse Abdul. jQuery UI Overview  jQuery UI javascript library Includes all UI component functionality  jQuery UI CSS framework Includes standard.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 2- JavaScript in Action Modern JavaScript Design And Develop Copyright © 2012 by Larry.
The Dr ü G Book: An Intro to Drupal The Dr ü G Book: An Intro to Drupal (Dr ü G: Drupal User ’ s Group - users, not developers) This is an introduction.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
ASP.NET vNEXT & development tools Marco De
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
ASP.NET 5 Visual Studio 2015 Templates Bill Wolff Rob Keiser June 10, 2015.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
Sascha Wener.  Definition from Microsoft Developer Network: “A theme is a unified set of design elements and color schemes that you apply to pages to.
® IBM Software Group © 2006 IBM Corporation JSF Tree Control This Learning Module describes the use of the JSF Tree Control – for hierarchical organization.
Eclipse Overview Introduction to Web Programming Kirkwood Continuing Education Fred McClurg © Copyright 2015, Fred McClurg, All Rights Reserved.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Session 1 SESSION 1 Working with Dreamweaver 8.0.
ASP Introduction Y.-H. Chen International College Ming-Chuan University Fall, 2004.
Chapter 8 Cookies And Security JavaScript, Third Edition.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
1 JavaScript in Context. Server-Side Programming.
Lecture Note 1: Getting Started With ASP.  Introduction to ASP  Introduction to ASP An ASP file can contain text, HTML tags and scripts. Scripts in.
An Introduction to Front-end Web Development Tom Perkins.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 13 Templates.
Roll Screen Development Debugging assistance for building Rocks Rolls with screens OSGC, May 2008 Nadya Williams University of Zurich.
Internationalization in ASP.NET 2.0. SQL Server 2005 – Data Columns Use Unicode datatypes in: Table columns, CONVERT() and CAST() operations Use Unicode.
AMD and RequireJS Splitting JavaScript Code into Dependent Modules Software University Technical Trainers SoftUni Team.
Web Design and Development. World Wide Web  World Wide Web (WWW or W3), collection of globally distributed text and multimedia documents and files 
Unit 10 – JavaScript Validation Instructor: Brent Presley.
© Copyright 2011 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice. HP Restricted Module 11.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
Kendo Ui Basics.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP. ASP is a powerful tool for making dynamic and interactive Web pages An ASP file can contain text, HTML tags and scripts. Scripts in an ASP file are.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
Bundles, Minification Andres Käver, IT Kolledž
Internationalization Andres Käver, IT Kolledž 2015.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
JQUERY AND AJAX
TypeScript for Alfresco and CMIS Steve Reiner CTO Integrated Semantics.
Building an End-to-End HTML5 App with ASP.NET MVC, EF and jQuery Dan Wahlin.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Editing and Debugging Mumps with VistA and the Eclipse IDE Joel L. Ivey, Ph.D. Dept. of Veteran Affairs OI&T, Veterans Health IT Infrastructure & Security.
Online Conference June 17 th and 18 th Modern SharePoint Development using Visual Studio Code.
//liveVirtualacademy2011/ What’s New for ASP.NET 4.5 and Web Development in Visual Studio 11 Developer Preview Γιώργος Καπνιάς MVP, MCT, MCDP, MCDBA, MCTS,
1 Cutting Edge FE technologies for complex product August 6, 2015.
CSCI 3100 Tutorial 5 Bootstrap & Git ZENG, Jichuan Department of Computer Science and Engineering The Chinese University of Hong.
Node.js Modules Header Mastering Node.js, Part 2 Eric W. Greene
Introduction to MEAN (JavaScript Full Stack Development)
NodeJS and MEAN cs6320.
Building Web Applications with Microsoft ASP
Modules, Babel, RequireJS, Other JavaScript Module Systems
IBM Rational Rhapsody Advanced Systems Training v7.5
Building Web Applications with Microsoft ASP
Play Framework: Introduction
NodeJS and MEAN Prof. L. Grewe.
Creating Custom Conversion Themes
3 Things Everyone Knows About Node JS That You Don't
14 A Brief Look at JavaScript and jQuery.
Introduction to SharePoint Framework (SPFx)
Introduction to SharePoint Framework (SPFx)
Introduction to SharePoint Framework
Today’s Objectives Week 12 Announcements ASP.NET
Cordova & Cordova Plugin Installation and Management
Introduction to Sitecore JSS for frontend and backend developers
Carthage ios 8 onwards Dependency manager that streamlines the process of integrating the libraries into the project.
Presentation transcript:

I18n - DateTime ASP.NET MVC

I18n DateTime – EF changes  In model classes, use attributes  DataType(DataType.DateTime)  DataType(DataType.Date)  DataType(DataType.Time)  Configure EF [DataType(DataType.DateTime)] public DateTime DateTime { get; set; } [DataType(DataType.Date)] public DateTime Date { get; set; } [DataType(DataType.Time)] public DateTime Time { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { // convert all datetime and datetime? properties to datetime2 in ms sql // ms sql datetime has min value of :00: modelBuilder.Properties ().Configure(c => c.HasColumnType("datetime2")); // use Date type in ms sql, where [DataType(DataType.Date)] attribute is used modelBuilder.Properties ().Where(x => x.GetCustomAttributes(false).OfType ().Any(a => a.DataType == DataType.Date)).Configure(c => c.HasColumnType("date")); }

I18n - browsers  Chrome/Edge adds html5 support (but only in en-US format…)  Cant submit, will not validate on serverside (format mismatch between server and browser)

I18n - browsers  Firefox – no extra support  Unobtrusive (jquery) validation also fails

I18n  Solutions  Use simple text fields and dropdowns, skip direct clientside datetime validation  Can be problematic, different regions are used to their own way of seeing culture support (money, time, commas, etc)  Use js plugins to generate html and validate inputs – jquery  Hard to setup correctly  Jquery unobtrusive validate initially supports only en-US  Several jquery/bootstrap plugins to generate html inputs for datetime

I18n – jquery validation  Jquery needs several js packages  Nuget does not have all of them, or latest versions of them  ASP.NET Core will not use Nuget for clientside package management.  node.js - JavaScript runtime built on Chrome's V8 JavaScript engine.  npm – package manager for node.js modules  bower - a package manager for the web components  grunt/gulp – js task runner (minify, zip, etc)

I18n – frontend tooling  Download and install node.js – stable version  Includes npm  Install bower  npm install -g bower (from command line)  npm install -g cldr-data-downloader  Install git command line (

i18n – get project components  Cd into VS solution root directory  Web is name of the MVC project folder in solution  Setup bower in project root  Create file named.bowerrc  Create bower.json file  bower init  Use default answers initially  Install required scripts  bower install globalize -save { "directory" : "Web/bower_components", "scripts" : { }

i18n – get project components  Download CLDR data (json files, descripting locales) node %USERPROFILE%\AppData\Roaming\npm\node_modules\cldr- data-downloader\bin\download.js -i Web\bower_components\cldr-data\index.json -o Web\bower_components\cldr-data\  Install moment.js  bower install moment –save  Install bootstrap datetimepicker  bower install eonasdan-bootstrap-datetimepicker#latest --save

i18n – get project components  Install bootstrap  bower install bootstrap --save  Install respond  bower install respond --save  Install tinymce (if you want to edit texts in wysiwyg format)  Bower install tinymce –save

I18n – custom scripts  Jquery.validate.globalize does not support time and datetime validation. BaseApps/blob/master/ContactApp/Web/Scripts/App/jquery.validate.globalize.datetime.js... $.validator.methods.datetimeGlobalizeOptions = { dateParseFormat: [{ skeleton: "yMdHm" }, { datetime: "short" }, { datetime: "medium" }, { datetime: "long" }, { datetime: "full" }] }; // additional method $.validator.methods.datetime = function (value, element) { // is it optional if (this.optional(element) === true) return true; // remove spaces just in case value = value.trim(); var res = false; var val; for (var i = 0; i < $.validator.methods.datetimeGlobalizeOptions.dateParseFormat.length; i++) { val = Globalize.parseDate(value, $.validator.methods.datetimeGlobalizeOptions.dateParseFormat[i]); res = res || (val instanceof Date); if (res === true) return res; } return res; }; //create adapters for new type - so they will be attached automatically //this depends on attribute data-val-time, data-val-datetime $.validator.unobtrusive.adapters.addBool('datetime'); }(jQuery, Globalize));

I18n – custom scripts  BaseApps/blob/master/ContactApp/Web/Scripts/App/jquery.validate.fixdata.js $(function () { // replace html5 datetime, date and time types on inputs - this disables builtin html5 editors in browsers // add data-type attribute instead $('input[type="datetime"]').attr('type', 'text').attr('data-type', 'datetime'); $('input[type="date"]').attr('type', 'text').attr('data-type', 'date'); $('input[type="time"]').attr('type', 'text').attr('data-type', 'time'); // fix up attributes for datetime var attr = $('input[data-type="datetime"]:first'); var attrText; if (attr.length === 1) { attrText = attr.eq(0).attr('data-val-date'); if (attrText != undefined) { attrText = attrText.replace('date.', 'datetime.'); $('input[data-type="datetime"]').removeAttr('data-val-date'); $('input[data-type="datetime"]').attr('data-val-datetime', attrText); } else { // TODO: translations $('input[data-type="datetime"]').attr('data-val-datetime', 'Field has to be of type datetime.'); } // fix up attributes for time // TODO: translations $('input[data-type="time"]').attr('data-val-time', 'Field has to be of type time.'); });

I18n – save culture code for js // set up global js variable, to hold culture code var currentCultureCode = "root"; switch (Thread.CurrentThread.CurrentCulture.ToString()) { case "et-EE": currentCultureCode = "et"; break; case "en-US": currentCultureCode = "en"; break; default: currentCultureCode = Thread.CurrentThread.CurrentCulture.ToString(); break; - My var currentCultureCode =

I18n – modify html via js – app.js  Load cldr data, initialize Globalize and moment var currentCultureCode; //global variable, created in _Layout.cshtml - et, en, etc $.when( $.get("/bower_components/cldr-data/supplemental/likelySubtags.json"), $.get("/bower_components/cldr-data/main/" + currentCultureCode + "/numbers.json"), $.get("/bower_components/cldr-data/supplemental/numberingSystems.json"), $.get("/bower_components/cldr-data/main/" + currentCultureCode + "/ca-gregorian.json"), $.get("/bower_components/cldr-data/main/" + currentCultureCode + "/ca-generic.json"), $.get("/bower_components/cldr-data/main/" + currentCultureCode + "/timeZoneNames.json"), $.get("/bower_components/cldr-data/supplemental/timeData.json"), $.get("/bower_components/cldr-data/supplemental/weekData.json") ).then(function () { // Normalize $.get results, we only need the JSON, not the request statuses. return [].slice.apply(arguments, [0]).map(function (result) { return result[0]; }); }).then(Globalize.load).then(function () { // Initialise Globalize to the current UI culture Globalize.locale(currentCultureCode); moment.locale(currentCultureCode); });...

I18n – modify html via js – app.js  Harmonize moment/globalize  Attach datetimepicker  Set up html placeholders $(function () { // fix specific locale problems in moment.js // moment is not using cldr data yet moment.localeData("et")._longDateFormat.LT = "HH:mm"; // attach bootstrap datetimepicker spinner $('[data-type="datetime"]').datetimepicker({ locale: currentCultureCode, format: 'L LT' }); $('[data-type="date"]').datetimepicker({ locale: currentCultureCode, format: 'L' }); $('[data-type="time"]').datetimepicker({ locale: currentCultureCode, format: 'LT' }); //add placeholders, use moment.js formats - since datetimepicker uses it $('[data-type="datetime"]').attr('placeholder', moment.localeData(currentCultureCode)._longDateFormat.L + " " + moment.localeData(currentCultureCode)._longDateFormat.LT); $('[data-type="date"]').attr('placeholder', moment.localeData(currentCultureCode)._longDateFormat.L); $('[data-type="time"]').attr('placeholder', moment.localeData(currentCultureCode)._longDateFormat.LT); });

i18n – set up js bundles public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/bundles/jquery").Include( "~/bower_components/jquery/dist/jquery.js")); bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( "~/Scripts/app/jquery.validate.fixdata.js", "~/bower_components/jquery-validation/dist/jquery.validate.js", "~/Scripts/jquery.validate.unobtrusive.js", // original ms package "~/Scripts/app/jquery.validate.globalize.datetime.js" )); bundles.Add(new ScriptBundle("~/bundles/cldr").Include( "~/bower_components/cldrjs/dist/cldr.js", "~/bower_components/cldrjs/dist/cldr/event.js", "~/bower_components/cldrjs/dist/cldr/supplemental.js", "~/bower_components/cldrjs/dist/cldr/unresolved.js")); bundles.Add(new ScriptBundle("~/bundles/globalize").Include( "~/bower_components/globalize/dist/globalize.js", "~/bower_components/globalize/dist/globalize/number.js", "~/bower_components/globalize/dist/globalize/*.js" )); bundles.Add(new ScriptBundle("~/bundles/moment").Include( "~/bower_components/moment/min/moment-with-locales.js"));

i18n – set up js bundles // Use the development version of Modernizr to develop with and learn from. Then, when you're // ready for production, use the build tool at to pick only the tests you need. bundles.Add(new ScriptBundle("~/bundles/modernizr").Include( "~/Scripts/modernizr-*")); bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include( "~/bower_components/bootstrap/dist/js/bootstrap.js", "~/bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js", "~/bower_components/respond/respond.min.js")); bundles.Add(new StyleBundle("~/Content/css").Include( "~/bower_components/bootstrap/dist/css/bootstrap.css", "~/bower_components/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.css", "~/Content/site.css")); bundles.Add(new ScriptBundle("~/bundles/app").Include( "~/Scripts/app/app.js")); BundleTable.EnableOptimizations = false; }

i18n – use bundles to reference scripts (_Layout.cshtml)  End of @RenderSection("scripts", required: false)

I18n – DateTime.ToString()  Change default DateTime ToString functionality protected void Application_BeginRequest() { // modify datetime.tostring formating in estonian locale (remove seconds) // default format is: ShortDatePattern + ' ' + LongTimePattern if (CultureInfo.CurrentCulture.Name.StartsWith("et")) { var culture = (CultureInfo)CultureInfo.CurrentCulture.Clone(); culture.DateTimeFormat.LongTimePattern = "HH:mm"; Thread.CurrentThread.CurrentCulture = culture; }

i18n – chrome/firefox

i18n – bower  Final bower.json file  Restore bower packages described in bower.json  bower install  Update all installed packages  bower update { "name": "Web", "authors": ["Andres Käver "], "description": "", "main": "", "moduleType": [ ], "license": "MIT", "homepage": "", "ignore": [ "**/.*", "node_modules", "bower_components", "Web/bower_components", "test", "tests" ], "dependencies": { "globalize": "^1.1.1", "cldr-data": "^29.0.0", "moment": "^2.12.0", "eonasdan-bootstrap-datetimepicker": "^ ", "bootstrap": "^3.3.6", "respond": "^1.4.2", "tinymce": "^4.3.8" }

i18n – bower  Bower list C:\!dev\git\ASP.NET-BaseApps\ContactApp>bower list bower check-new Checking for new versions of the project dependencies... Web C:\!dev\git\ASP.NET-BaseApps\ContactApp ├─┬ bootstrap#3.3.6 (latest is alpha.2) │ └── jquery#2.2.2 (latest is beta1) ├── cldr-data# ├─┬ eonasdan-bootstrap-datetimepicker# │ ├── jquery#2.2.2 (3.0.0-beta1 available) │ ├── moment# │ └─┬ moment-timezone#0.5.3 │ └── moment# ├─┬ globalize#1.1.1 │ ├── cldr-data# │ └─┬ cldrjs#0.4.4 │ └── cldr-data# ├── moment# ├── respond#1.4.2 └── tinymce#4.3.8

I18n – code management  Do not commit bower_components into code repository  Meaningless mirror of github projects…  Other team members will get bower.json and do bower install/update  Using git  in.gitignore add line /bower_components  In VS, include files into project  Probably do not include full cldr-data/main folder. Just pick required locales (et, en-GB, etc)

THE END

Materials  management-part-1 management-part-1  client-side-dependencies-with-npm-bower-and-gulp client-side-dependencies-with-npm-bower-and-gulp   want/#/?currency=true&date=true&message=true&number=true& plural=true&relativeTime=true&unit=true want/#/?currency=true&date=true&message=true&number=true& plural=true&relativeTime=true&unit=true