• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Sanity check on behaviour of ERXLocalizer's fileNamesToWatch property
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sanity check on behaviour of ERXLocalizer's fileNamesToWatch property


  • Subject: Sanity check on behaviour of ERXLocalizer's fileNamesToWatch property
  • From: Paul Hoadley <email@hidden>
  • Date: Tue, 16 Feb 2016 12:28:05 +1030

Hello,

It wouldn’t be the first time that I was the last person to discover some, err, idiosyncratic behaviour or other, but here’s one for the archives.

I’m using some features of ERXProperties and ERXLocalizer to be able to deploy multiple “products” from a single codebase, where by “product” I really just mean a lightly customised view of an app for a particular class of end user. One of the customisations is the user-presentable names for entities and some of their properties, and other labels within the app. Setting a property like this at launch time:

-Dproduct.name=Foo

allows me to do something like this in Properties:

er.extensions.ERXProperties.OptionalConfigurationFiles=(@@product.name@@.properties)

which then loads the custom Foo.properties. That file sets fileNamesToWatch like this:

er.extensions.ERXLocalizer.fileNamesToWatch=("Foo-Localizable.strings", "Foo-ValidationTemplate.strings")

In development, after setting this up, I was seeing the custom Localizable.strings, but _not_ the ValidationTemplate.strings—none of the keys (say, "Foo.bar.MandatoryToOneRelationshipException") were being found. Closer inspection shows what it’s actually looking for is: “ValidationTemplate.Foo.bar.MandatoryToOneRelationshipException”. What’s happening is this in ERXLocalizer.load():

// HACK: ak we have could have a collision between the search path for validation strings and
// the normal localized strings.
if (fileName.indexOf(ERXValidationFactory.VALIDATION_TEMPLATE_PREFIX) == 0) {
NSMutableDictionary<String, Object> newDict = new NSMutableDictionary<String, Object>();
for (Enumeration<String> keys = dict.keyEnumerator(); keys.hasMoreElements();) {
String key = keys.nextElement();
newDict.setObjectForKey(dict.objectForKey(key), ERXValidationFactory.VALIDATION_TEMPLATE_PREFIX + key);
}
dict = newDict;
}

That is, if the _filename_ you’re loading from _starts with_ “ValidationTemplate”, then we prefix every property with “ValidationTemplate.”. And, indeed, that’s what’s being searched for by ERXValidationFactory:

public String templateForKeyPath(String key, String language) {
    return (String)ERXLocalizer.localizerForLanguage(language).valueForKey(VALIDATION_TEMPLATE_PREFIX + key);
}

The solution here is to either rename “Foo-ValidationTemplate.strings” to, say, “ValidationTemplate-Foo.strings” or prefix every property with “ValidationTemplate”. Trap for young players. And me.


-- 
Paul Hoadley
http://logicsquad.net/



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Sanity check on behaviour of ERXLocalizer's fileNamesToWatch property
      • From: Paul Hoadley <email@hidden>
  • Prev by Date: Re: Quickie: are subfolders for WOComponents allowed?
  • Next by Date: Re: Sanity check on behaviour of ERXLocalizer's fileNamesToWatch property
  • Previous by thread: Re: Quickie: are subfolders for WOComponents allowed?
  • Next by thread: Re: Sanity check on behaviour of ERXLocalizer's fileNamesToWatch property
  • Index(es):
    • Date
    • Thread