Closed akirk closed 5 years ago
Related #37
From a coding standpoint I'd suggest to return true
or false
in initialize_locale_bucket()
and introduce a $this->initalized
class variable and check for that before accessing the localized
array.
As a continuation, you could introduce a class CLDR_Exception extends Exception {}
and use throw new CLDR_Exception( 'missing JSON file' )
in the initializing.
This makes sense. I see a few separate issues:
initialize_locale_bucket()
. Having that method return true
or false
makes sense. I don't think we'd need a $this->initialized
class variable since we can just check isset( $this->localized... )
. Related, because of the way English fallbacks are handled a locale may be "initialized" and in memory but just have English data. It would be better to avoid "initializing" those locales. I'll do that and move the fallback logic into get_locale_bucket()
.get_available_languages()
?) and then display a message if any don't map to an installed CLDR JSON file.@akirk, how did you get to the screenshot above? did you have to delete one of the CLDR files or did you get that with a fresh install of the plugin?
I renamed the json
directory. I know it's not quite the fair thing to do but it was intended as preparation for the separate JSON downloading.
OK @akirk I just added another commit https://github.com/Automattic/wp-cldr/commit/102ee31fdc39c8ffa49b02d3dfde256ab529b12a to PR #76. I think that PR now addresses this issue. The diff is a bit messy but it:
get_cldr_json_file()
to create a few new methods -- get_cldr_json_path()
and is_cldr_json_available()
-- so that we can access them directlyinitialize_locale_bucket()
to create a new method -- get_best_available_cldr_json_locale()
-- that isolates the logic around language variation fallbacks. Also returns false if we cannot initialize the bucket.isset()
checks to a few of the newish methods in the classsomething is off with caching so I've disabled it for now I'll figure that out tomorrow.
Plugin page when selecting a locale without JSON files:
Plugin page when entire JSON directory is gone:
closing as this as https://github.com/Automattic/wp-cldr/pull/76 was merged
In light of potentially downloading the CLDR files separately, missing files should be handled better.
Currently the WP CLDR demo page looks like this:
Probably it would be useful to display a notice in WP-Admin about the missing files.