• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Question about localization for OCPJP8

 
Ranch Hand
Posts: 90
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,


I have a question about the following example, inspired from OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (page 265-266).

Suppose I have the following properties files:

Zoo_en.properties
hello=Hello
open=is open


Zoo_en_CA.properties
visitor=Canada visitor

Zoo_fr.properties
hello=Bonjour
open=est ouvert


Zoo_fr_CA.properties
visitor=Canada visiteur
name=Zoo de Vancouver


TestClass.java

From what I understand (see table 5.7 on page 264), Java looks first into Zoo_en_CA.properties (requested locale) and doesn't find the key. Then it looks into Zoo_en.properties (requested language with no country) and doesn't find the key. Finally, it looks into Zoo_fr_CA.properties (default locale) and finds the key.

So why do I get a java.util.MissingResourceException when running this code? Can anyone tell me where I'm wrong?

Thanks in advance.


Kind regards,
Guillaume
 
Guillaume Bailly
Ranch Hand
Posts: 90
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, ok, this one was simple, but I could not figure it out until the end of the chapter where it says:

Once a matching resource bundle is found, Java only looks in the hierarchy of that resource bundle to find keys.



So it will not combine the different properties files to find all the keys if they are spread.
 
author & internet detective
Posts: 42011
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Guillaume Bailly wrote:So it will not combine the different properties files to find all the keys if they are spread.


This is kind of an English thing, but not quite.

Suppose the first property is found in Zoo_en_CA.properties. It will look at Zoo_en.properties for future matches. It won't look in Zoo_fr.properties because it got excited about finding a match and knows where to look for more 0 in the match and it's parent(s).
 
Guillaume Bailly
Ranch Hand
Posts: 90
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, got it! Thanks for the explanation.
 
So I left, I came home, and I ate some pie. And then I read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic