SlideShare a Scribd company logo
1 of 15
www.SunilOS.com 1
www.sunilos.com
www.raystec.com
Resource Bundle
www.SunilOS.com 2
Introduction
It is used to support multi-language in an
Application that is called internationalization
(i18n).
It is used to remove hard coding from an
application by making configuration files and
read from resource bundle.
It moves all configurable parameters into a
text file in form of key=value pairs.
Class Hierarchy
www.SunilOS.com
3
Resource Bundle
PropertyResourceBundle ListResourceBundle
www.SunilOS.com 4
app.properties – create file
Create a text file having extension .properties.
Add key=value pairs of configurable data. Entries
will look like:
o #Database connection Parameters
o url=jdbc:mysql://localhost:3306/ocha
o driver=com.mysql.jdbc.Driver
o username=root
o password=pwd
Read from ResourceBundle
 Assuming that text file app.properties file is kept in
in.co.sunrays.rb package.
 public static void main(String[] args) {
 ResourceBundle rb =
 ResourceBundle.getBundle("in.co.sunrays.rb.app");
 //Pass key and get value
 String url = rb.getString("url");
 String driver = rb.getString("driver");
 String user = rb.getString("username");
 String password = rb.getString("password");
 }
www.SunilOS.com 5
Multilanguage Support
Can be achieved by setting Locale to resource
bundle.
For each locale you have to create a separate
.properties file.
Suppose you have to support three languages
English ( default ), Hindi and Spanish then you will
create:
o app.properties (default is English)
o app_hi.properties ( for Hindi )
o app_sp.properties ( for Spanish )
www.SunilOS.com 6
Create Property Files
app.properties
o greeting=Hello, how are you?
app_hi.properties
o greeting=हैलो, कै से हो?
app_sp.properties
o greeting=Hola, cómo estás?
www.SunilOS.com 7
www.SunilOS.com 8
Run and see the output
 //Default Locale
 ResourceBundle rb = ResourceBundle.getBundle("in.co.sunrays.rb.app");
 System.out.println(rb.getString("greeting"));
 //Set Locale to Spanish
 rb = ResourceBundle.getBundle("in.co.sunrays.rb.app", new Locale("sp"));
 System.out.println(rb.getString("greeting"));
 //Set Locale to Hindi
 rb = ResourceBundle.getBundle("in.co.sunrays.rb.app", new Locale("hi"));
 System.out.println(rb.getString("greeting"));
 Output
o Hello, how are you?
 Hola, cómo estás?
 हैलो, कै से हो?
Multi-Language Support
www.SunilOS.com 9
What is Locale?
A Locale object represents a specific geographical,
political, or cultural region.
Locale has three constructors that accepts:
o Language : uses two character code to represent a
language
 i.e. en : English, sp: Spanish, hi : Hindi
o Country : accepts valid international country code
 i.e. US: USA, IN : India, UK : United Kingdom.
o Variant: any arbitrary value used to indicate a variation
of a Locale, say state name MP, UP, HP, NY, TX, CT
etc.
www.SunilOS.com 10
Locale Constructors
Constructors:
o Locale(String language)
o Locale(String language, String country)
o Locale(String language, String country, String variant)
Locale locale = new Locale(“hi", “IN");
o It searches key in app_hi_IN.properties file.
Locale locale = new Locale(“hi", “IN“,”UP”);
o It searches key in app_hi_IN_UP.properties file.
www.SunilOS.com 11
Say NO to
Hard Coding
www.SunilOS.com 12
Say YES to
Resource Bundle
www.SunilOS.com 13
Disclaimer
This is an educational presentation to enhance the
skill of computer science students.
This presentation is available for free to computer
science students.
Some internet images from different URLs are
used in this presentation to simplify technical
examples and correlate examples with the real
world.
We are grateful to owners of these URLs and
pictures.
www.SunilOS.com 14
Thank You!
www.SunilOS.com 15
www.SunilOS.com

More Related Content

What's hot

JavaScript
JavaScriptJavaScript
JavaScriptSunil OS
 
Collections Framework
Collections FrameworkCollections Framework
Collections FrameworkSunil OS
 
Exception Handling
Exception HandlingException Handling
Exception HandlingSunil OS
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File HandlingSunil OS
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and OperatorsSunil OS
 
Python Part 1
Python Part 1Python Part 1
Python Part 1Sunil OS
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )Sunil OS
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and ConcurrencySunil OS
 
Data Persistence in Android with Room Library
Data Persistence in Android with Room LibraryData Persistence in Android with Room Library
Data Persistence in Android with Room LibraryReinvently
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performanceintelliyole
 

What's hot (20)

Log4 J
Log4 JLog4 J
Log4 J
 
JavaScript
JavaScriptJavaScript
JavaScript
 
OOP V3.1
OOP V3.1OOP V3.1
OOP V3.1
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
 
CSS
CSS CSS
CSS
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
C++
C++C++
C++
 
Machine learning ( Part 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )
 
PDBC
PDBCPDBC
PDBC
 
C++ oop
C++ oopC++ oop
C++ oop
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
 
Data Persistence in Android with Room Library
Data Persistence in Android with Room LibraryData Persistence in Android with Room Library
Data Persistence in Android with Room Library
 
Php functions
Php functionsPhp functions
Php functions
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performance
 

Viewers also liked

C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFCSunil OS
 
Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Eschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School SoftwareEschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School SoftwareMayank Jain
 
Développer avec le sylius resourcebundle (Symfony live Paris 2015)
Développer avec le sylius resourcebundle (Symfony live Paris 2015) Développer avec le sylius resourcebundle (Symfony live Paris 2015)
Développer avec le sylius resourcebundle (Symfony live Paris 2015) Arnaud Langlade
 

Viewers also liked (7)

C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFC
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Cvl bundle presentation
Cvl bundle presentationCvl bundle presentation
Cvl bundle presentation
 
Eschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School SoftwareEschool erp School Management System SMS System School Software
Eschool erp School Management System SMS System School Software
 
Développer avec le sylius resourcebundle (Symfony live Paris 2015)
Développer avec le sylius resourcebundle (Symfony live Paris 2015) Développer avec le sylius resourcebundle (Symfony live Paris 2015)
Développer avec le sylius resourcebundle (Symfony live Paris 2015)
 

Similar to Resource Bundle

Android App Development 08 : Support Multiple Devices
Android App Development 08 : Support Multiple DevicesAndroid App Development 08 : Support Multiple Devices
Android App Development 08 : Support Multiple DevicesAnuchit Chalothorn
 
Multi Lingual Websites In Umbraco
Multi Lingual Websites In UmbracoMulti Lingual Websites In Umbraco
Multi Lingual Websites In UmbracoPaul Marden
 
Internationlization
InternationlizationInternationlization
InternationlizationTuan Ngo
 
Android structure
Android structureAndroid structure
Android structureKumar
 
Globalization and accessibility
Globalization and accessibilityGlobalization and accessibility
Globalization and accessibilityaspnet123
 
Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Stephan Hochdörfer
 
Android resource
Android resourceAndroid resource
Android resourceKrazy Koder
 
Practical Internationalization Improvement for Sakai CLE
Practical Internationalization Improvement for Sakai CLEPractical Internationalization Improvement for Sakai CLE
Practical Internationalization Improvement for Sakai CLEjfl_101010
 
Localization
LocalizationLocalization
Localizationlokesh s
 
Application fundamentals
Application fundamentalsApplication fundamentals
Application fundamentalsmaamir farooq
 
Data Science Amsterdam - Massively Parallel Processing with Procedural Languages
Data Science Amsterdam - Massively Parallel Processing with Procedural LanguagesData Science Amsterdam - Massively Parallel Processing with Procedural Languages
Data Science Amsterdam - Massively Parallel Processing with Procedural LanguagesIan Huston
 
Drupal 8 Multilingual - what to look forward to
Drupal 8 Multilingual - what to look forward toDrupal 8 Multilingual - what to look forward to
Drupal 8 Multilingual - what to look forward toGábor Hojtsy
 
Drupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire WorldDrupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire WorldChristian López Espínola
 
A whole new world for multilingual sites in Drupal 8 - jam's Drupal Camp session
A whole new world for multilingual sites in Drupal 8 - jam's Drupal Camp sessionA whole new world for multilingual sites in Drupal 8 - jam's Drupal Camp session
A whole new world for multilingual sites in Drupal 8 - jam's Drupal Camp sessionJeffrey McGuire
 

Similar to Resource Bundle (20)

Android App Development 08 : Support Multiple Devices
Android App Development 08 : Support Multiple DevicesAndroid App Development 08 : Support Multiple Devices
Android App Development 08 : Support Multiple Devices
 
Internationalization
InternationalizationInternationalization
Internationalization
 
Multi Lingual Websites In Umbraco
Multi Lingual Websites In UmbracoMulti Lingual Websites In Umbraco
Multi Lingual Websites In Umbraco
 
Internationlization
InternationlizationInternationlization
Internationlization
 
147 341-1-pb baik
147 341-1-pb baik147 341-1-pb baik
147 341-1-pb baik
 
Android structure
Android structureAndroid structure
Android structure
 
MIDP Internalization
MIDP InternalizationMIDP Internalization
MIDP Internalization
 
Globalization and accessibility
Globalization and accessibilityGlobalization and accessibility
Globalization and accessibility
 
NetBase API Presentation
NetBase API PresentationNetBase API Presentation
NetBase API Presentation
 
Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13
 
Android resource
Android resourceAndroid resource
Android resource
 
Practical Internationalization Improvement for Sakai CLE
Practical Internationalization Improvement for Sakai CLEPractical Internationalization Improvement for Sakai CLE
Practical Internationalization Improvement for Sakai CLE
 
Localization
LocalizationLocalization
Localization
 
Application fundamentals
Application fundamentalsApplication fundamentals
Application fundamentals
 
Data Science Amsterdam - Massively Parallel Processing with Procedural Languages
Data Science Amsterdam - Massively Parallel Processing with Procedural LanguagesData Science Amsterdam - Massively Parallel Processing with Procedural Languages
Data Science Amsterdam - Massively Parallel Processing with Procedural Languages
 
Drupal 8 Multilingual - what to look forward to
Drupal 8 Multilingual - what to look forward toDrupal 8 Multilingual - what to look forward to
Drupal 8 Multilingual - what to look forward to
 
Unit 4 lecture-3
Unit 4 lecture-3Unit 4 lecture-3
Unit 4 lecture-3
 
Drupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire WorldDrupal 8's Multilingual APIs: Building for the Entire World
Drupal 8's Multilingual APIs: Building for the Entire World
 
A whole new world for multilingual sites in Drupal 8 - jam's Drupal Camp session
A whole new world for multilingual sites in Drupal 8 - jam's Drupal Camp sessionA whole new world for multilingual sites in Drupal 8 - jam's Drupal Camp session
A whole new world for multilingual sites in Drupal 8 - jam's Drupal Camp session
 
Submission_36
Submission_36Submission_36
Submission_36
 

More from Sunil OS

Threads v3
Threads v3Threads v3
Threads v3Sunil OS
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3Sunil OS
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )Sunil OS
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )Sunil OS
 
Python Pandas
Python PandasPython Pandas
Python PandasSunil OS
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1Sunil OS
 
Angular 8
Angular 8 Angular 8
Angular 8 Sunil OS
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays TechnologiesSunil OS
 

More from Sunil OS (11)

DJango
DJangoDJango
DJango
 
OOP v3
OOP v3OOP v3
OOP v3
 
Threads v3
Threads v3Threads v3
Threads v3
 
Exception Handling v3
Exception Handling v3Exception Handling v3
Exception Handling v3
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )
 
Machine learning ( Part 1 )
Machine learning ( Part 1 )Machine learning ( Part 1 )
Machine learning ( Part 1 )
 
Python Pandas
Python PandasPython Pandas
Python Pandas
 
Python part2 v1
Python part2 v1Python part2 v1
Python part2 v1
 
Angular 8
Angular 8 Angular 8
Angular 8
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays Technologies
 
C Basics
C BasicsC Basics
C Basics
 

Recently uploaded

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 

Recently uploaded (20)

social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 

Resource Bundle

  • 2. www.SunilOS.com 2 Introduction It is used to support multi-language in an Application that is called internationalization (i18n). It is used to remove hard coding from an application by making configuration files and read from resource bundle. It moves all configurable parameters into a text file in form of key=value pairs.
  • 4. www.SunilOS.com 4 app.properties – create file Create a text file having extension .properties. Add key=value pairs of configurable data. Entries will look like: o #Database connection Parameters o url=jdbc:mysql://localhost:3306/ocha o driver=com.mysql.jdbc.Driver o username=root o password=pwd
  • 5. Read from ResourceBundle  Assuming that text file app.properties file is kept in in.co.sunrays.rb package.  public static void main(String[] args) {  ResourceBundle rb =  ResourceBundle.getBundle("in.co.sunrays.rb.app");  //Pass key and get value  String url = rb.getString("url");  String driver = rb.getString("driver");  String user = rb.getString("username");  String password = rb.getString("password");  } www.SunilOS.com 5
  • 6. Multilanguage Support Can be achieved by setting Locale to resource bundle. For each locale you have to create a separate .properties file. Suppose you have to support three languages English ( default ), Hindi and Spanish then you will create: o app.properties (default is English) o app_hi.properties ( for Hindi ) o app_sp.properties ( for Spanish ) www.SunilOS.com 6
  • 7. Create Property Files app.properties o greeting=Hello, how are you? app_hi.properties o greeting=हैलो, कै से हो? app_sp.properties o greeting=Hola, cómo estás? www.SunilOS.com 7
  • 8. www.SunilOS.com 8 Run and see the output  //Default Locale  ResourceBundle rb = ResourceBundle.getBundle("in.co.sunrays.rb.app");  System.out.println(rb.getString("greeting"));  //Set Locale to Spanish  rb = ResourceBundle.getBundle("in.co.sunrays.rb.app", new Locale("sp"));  System.out.println(rb.getString("greeting"));  //Set Locale to Hindi  rb = ResourceBundle.getBundle("in.co.sunrays.rb.app", new Locale("hi"));  System.out.println(rb.getString("greeting"));  Output o Hello, how are you?  Hola, cómo estás?  हैलो, कै से हो?
  • 10. What is Locale? A Locale object represents a specific geographical, political, or cultural region. Locale has three constructors that accepts: o Language : uses two character code to represent a language  i.e. en : English, sp: Spanish, hi : Hindi o Country : accepts valid international country code  i.e. US: USA, IN : India, UK : United Kingdom. o Variant: any arbitrary value used to indicate a variation of a Locale, say state name MP, UP, HP, NY, TX, CT etc. www.SunilOS.com 10
  • 11. Locale Constructors Constructors: o Locale(String language) o Locale(String language, String country) o Locale(String language, String country, String variant) Locale locale = new Locale(“hi", “IN"); o It searches key in app_hi_IN.properties file. Locale locale = new Locale(“hi", “IN“,”UP”); o It searches key in app_hi_IN_UP.properties file. www.SunilOS.com 11
  • 12. Say NO to Hard Coding www.SunilOS.com 12
  • 13. Say YES to Resource Bundle www.SunilOS.com 13
  • 14. Disclaimer This is an educational presentation to enhance the skill of computer science students. This presentation is available for free to computer science students. Some internet images from different URLs are used in this presentation to simplify technical examples and correlate examples with the real world. We are grateful to owners of these URLs and pictures. www.SunilOS.com 14