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

Collections Framework
Collections FrameworkCollections Framework
Collections FrameworkSunil OS
 
Threads V4
Threads  V4Threads  V4
Threads V4Sunil 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
 
Exception Handling
Exception HandlingException Handling
Exception HandlingSunil OS
 
JavaScript
JavaScriptJavaScript
JavaScriptSunil OS
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )Sunil OS
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and OperatorsSunil OS
 
Java Basics
Java BasicsJava Basics
Java BasicsSunil OS
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and ConcurrencySunil OS
 
Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFCSunil OS
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfacesmadhavi patil
 
Angular 8
Angular 8 Angular 8
Angular 8 Sunil OS
 

What's hot (20)

Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
Threads V4
Threads  V4Threads  V4
Threads V4
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
JavaScript
JavaScriptJavaScript
JavaScript
 
Machine learning ( Part 3 )
Machine learning ( Part 3 )Machine learning ( Part 3 )
Machine learning ( Part 3 )
 
JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
 
OOP V3.1
OOP V3.1OOP V3.1
OOP V3.1
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java Threads and Concurrency
Java Threads and ConcurrencyJava Threads and Concurrency
Java Threads and Concurrency
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Java Swing JFC
Java Swing JFCJava Swing JFC
Java Swing JFC
 
Spring Core
Spring CoreSpring Core
Spring Core
 
Java RMI
Java RMIJava RMI
Java RMI
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
Java I/O
Java I/OJava I/O
Java I/O
 
Angular 8
Angular 8 Angular 8
Angular 8
 
django
djangodjango
django
 

Similar to Resource Bundle for Multi-Language Support

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 for Multi-Language Support (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 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )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
 
Python Part 1
Python Part 1Python Part 1
Python Part 1Sunil OS
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and OperatorsSunil OS
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays TechnologiesSunil OS
 

More from Sunil OS (16)

DJango
DJangoDJango
DJango
 
PDBC
PDBCPDBC
PDBC
 
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 2 )
Machine learning ( Part 2 )Machine learning ( Part 2 )
Machine learning ( Part 2 )
 
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
 
Python Part 1
Python Part 1Python Part 1
Python Part 1
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
C# Basics
C# BasicsC# Basics
C# Basics
 
Rays Technologies
Rays TechnologiesRays Technologies
Rays Technologies
 
C++ oop
C++ oopC++ oop
C++ oop
 
C++
C++C++
C++
 
C Basics
C BasicsC Basics
C Basics
 

Recently uploaded

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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Recently uploaded (20)

Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

Resource Bundle for Multi-Language Support

  • 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