Code: Select all
<?php
$localeSettings = new Settings(/* data source */); // properties file of EN.Warning="Warning" or database or whatever.
$local = new Locale($localeSettings);
$messages = new Messages($localeSettings);
?>Moderator: General Moderators
Code: Select all
<?php
$localeSettings = new Settings(/* data source */); // properties file of EN.Warning="Warning" or database or whatever.
$local = new Locale($localeSettings);
$messages = new Messages($localeSettings);
?>Objects are a good thing, while it would be a ton of objects, I think it is okay to have them. Even if it would not have an effect on the maintainability/scalability/portability/randombility of the application, it is still practice. If you are programming OO code, everything should be an object, right?Ambush Commander wrote:An object, then, for each currency. Presumably, the same would have to apply to dates, number formatting, etc. Inheritance used to prevent duplication. Which is a lot of objects!
Hmm... not sure what's going on in your code. Is Settings a generic configuration object?It all depends on your data layer it would seem.
Yes, lots of objects are good!Objects are a good thing, while it would be a ton of objects, I think it is okay to have them. Even if it would not have an effect on the maintainability/scalability/portability/randombility of the application, it is still practice. If you are programming OO code, everything should be an object, right?
Code: Select all
$locale = new Locale('en');
$m = $locale->getMessages();
echo $m->get('message-identifier');
$n = $locale->getNumberFormatter();
echo $n->format(83242833);
// etcCode: Select all
$locale = new Locale('en_AU');
$pattern = $locale->getCurrencyPattern();
$nf = new NumberFormatter();
echo $nf->format(12.0, $pattern); //may use custom patternCode: Select all
$source = new MessageSource(); //or more specific sources
$bundle = $source->getBundle('bundle1', $locale);
$mf = new MessageFormatter($source);
$mf->addBundle($bundle);
$result = $mf->format($message, $subsititutes);
$choice = new ChoiceFormatter();
echo $choice->format($result);Code: Select all
function format_message($msg, $subs, $locale);
function format_currency($value, $locale);
function format_decimal($value, $locale);
function format_xxx()Other locale settings? You mean like date formatting?Ambush Commander wrote:Right. Your system focuses solely on message substitution and not other localization related functions. As for modular language files, I don't think splitting them up will be necessary for my purposes (there shouldn't be that many).
This seems like $pattern becomes a dangling external dependency of both classes. Would something more direct be better?wei wrote:I prefer
Code: Select all
$locale = new Locale('en_AU'); $pattern = $locale->getCurrencyPattern(); $nf = new NumberFormatter(); echo $nf->format(12.0, $pattern); //may use custom pattern
Code: Select all
$locale = new Locale('en_AU');
$nf = new NumberFormatter($locale);
echo $nf->formatCurrency(12.0);