Open mlewand opened 9 years ago
Yes, localization as it stands is a very narrow solution. It was meant to be a bridge between no localization and a flexible solution.
Alright so lets start proposing some concepts / solutions.
The idea is to split localization into two files config and assessments.
lang/en/core.json
lang/en/assessments.json
Quail would load proper language file on demand (once $().quail is called with a given language).
Quail main object will store internal variable:
Quail._langs = {
en: {
core: {
// Dictionary...
},
assessments: {
// Dictionary...
}
},
nl: {
core: {
// Dictionary...
},
assessments: {
// Dictionary...
}
}
}
And localization values will be available with:
quail.lang( 'core.testability.moderate' );
Then for convenience Test collection would implement the following lang method:
Test.prototype.lang = function( propertyName ) {
// Reminder: this.attributes.name stores assessment id, e.g. `imgHasAlt`.
return this.quail.lang( 'assessments.' + this.attributes.name + '.' + propertyName );
}
Typical main Quail fn call might look sth like:
$( scope ).quail( {
lang: 'en',
resultsReady: function( results ) {
// This method is called when checking is done and results are ready.
// Result objects does **not contain any localizations** at this point. Only id, status.
},
resultsLoaded: function( results ) {
// This method has the same role as `resultsLoaded`, but here developer can access
// localized data (even synchronously).
var failedCollection = collection.findByStatus( 'failed' );
if ( failedCollection.length ) {
failedCollection.each( function( index, test ) {
// Note that we're accessing lang property synchronously here.
console.log( test.lang( 'title' ) );
} );
}
}
} );
Optimization: When building Quail, the builder will merge default lang's core.json
into Quail output .js
file. That way we don't need to request (wait) for core.json
to start checking in case of default language.
$( scope ).quail() called with lang='en'
.
quail._langs.en.core
exists.lang/en/core.json
. Once done store it and go to the next step.quail._langs.en.assessments
is undefined
, dispatch a request for lang/en/assessments.json
and continue.The point here is start request for assessments.json
so that it's downloaded during next step (Quail checking). There's a big chance that it's
going to be done by the time that Quail finishes checking.
options.resultsReady
method (we don't need assessments.json
here).quail._langs.en.assessments
is defined:
assessments.json
is loaded.options.resultsLoaded
.Splitting assessment files
Initially we wanted to split localization jsons per assessment, so that we'd have structure like:
lang/en/assessments/aImgAltNotRepetitive.json
lang/en/assessments/aAdjacentWithSameResourceShouldBeCombined.json
lang/en/assessments/aInPhasADistinctStyle.json
lang/en/assessments/aLinksDontOpenNewWindow.json
lang/en/assessments/imgHasAlt.json
But it would be useful only once #269 is done (putting assessments in their respective directory). In current shape it doesn't feel any better.
Then again, where will metadata be kept? That makes me really want #269 to be done first :)
I recall we were actually talking about dropping metadata completely. Actually we can't drop it, because it stores some vital information like type
(selector, event etc) or testability
.
meta.json
(or yml
) that will store meta for all the assessments..json
files and git. But I think we don't need it yet, simply json files will do for now. :)
We assume that current localization for
en
andnl
is just a temporary solution. But now, when we want Quail to be widely used, it's time to bring a real solution for multiple localizations.Issue #269 might be related.