@@ -3,6 +3,7 @@ import {getElementSizesInPx, getComputedStyle, getComputedPropertyValues
3
3
} from './domTool.mjs' ;
4
4
import WidgetsContainerWidget , { ID } from './WidgetsContainerWidget.mjs' ;
5
5
import { JustificationController , parseFontVariationSettings } from './justification.mjs' ;
6
+ import { getFromI18NConfig } from './typeSpec.mjs' ;
6
7
7
8
class _ContainerWidget {
8
9
constructor ( domTool , baseElement ) {
@@ -874,6 +875,7 @@ class InspectorWidget extends _ContainerWidget {
874
875
, reason = '(not set)'
875
876
, beacon = this . _targetElement . ownerDocument . querySelector (
876
877
`:not(.${ JUSTIFICATION_CONTEXT_BLOCK_CLASS } ) .${ INSPECTION_MODE_BEACON_CLASS } ` )
878
+ , debug = false
877
879
;
878
880
RECORDS:
879
881
for ( let rec of mutationRecords ) {
@@ -949,7 +951,7 @@ class InspectorWidget extends _ContainerWidget {
949
951
}
950
952
if ( ! reportNeedsUpdate )
951
953
return ;
952
- // console.warn('>>>> REPORT NEEDS UPDATE', reason);
954
+ debug && console . warn ( '>>>> REPORT NEEDS UPDATE' , reason ) ;
953
955
this . _updateReport ( ) ;
954
956
}
955
957
createtReport ( elem ) {
@@ -1224,8 +1226,8 @@ class InspectorWidget extends _ContainerWidget {
1224
1226
, report = ( type , element , shared ) => reports . push ( [
1225
1227
mkelem ( 'li' , [
1226
1228
mkfrac ( `<strong class="${ this . _class } -report_heading">${ key2label [ type ] || type } </strong>` )
1227
- , reporters . get ( reporters . has ( type ) ? type : undefined )
1228
- ( element , shared , type )
1229
+ , reporters . get ( reporters . has ( type )
1230
+ ? type : undefined ) ( element , shared , type )
1229
1231
] )
1230
1232
] )
1231
1233
;
@@ -1465,7 +1467,7 @@ function _runion_01_columns(columnConfig, availableWidthEn) {
1465
1467
}
1466
1468
// With a proper config this should not be possible (1 column min-width = 0),
1467
1469
// thus, if this happens we must look at the case and figure out what to do.
1468
- throw new Error ( `Can\ 't compose column setup for availableWidthEn: ${ availableWidthEn } !` ) ;
1470
+ throw new Error ( `Can't compose column setup for availableWidthEn: ${ availableWidthEn } !` ) ;
1469
1471
}
1470
1472
1471
1473
function _runion_01_lineHeight ( { minLineHeight, maxLineHeight,
@@ -1725,6 +1727,115 @@ function fixCSSKeyframes(document, cssKeyframeFixes) {
1725
1727
}
1726
1728
}
1727
1729
1730
+ function ucFirst ( str ) {
1731
+ return str . split ( '' )
1732
+ . map ( ( chr , i ) => i === 0
1733
+ ? chr . toUpperCase ( )
1734
+ : chr . toLowerCase ( )
1735
+ )
1736
+ . join ( '' ) ;
1737
+ }
1738
+
1739
+
1740
+ /**
1741
+ * As input expect a string with the locale order "{language}-{script}-{territory}"
1742
+ * but returns an array of [script, language, territory] as the order better
1743
+ * fits our internal logic. Also, each particle may be null if not found in the
1744
+ * string. There's no check if the particles actually exist (in CLDR) just
1745
+ * a formal length check and respective uppercase/lowercase treatments.
1746
+ * We also allow locales that don't bring a language and we try to produce
1747
+ * a script for languages that don't specify it.
1748
+ */
1749
+ function parseLocale ( locale ) {
1750
+ const parts = locale . split ( '-' ) ;
1751
+ let language = null
1752
+ , script = null
1753
+ , territory = null
1754
+ ;
1755
+ // A full locale looks like 'de-Latn-AT'
1756
+ // or fr-Latn-CA
1757
+ if ( parts . length && parts [ 0 ] . length === 2 )
1758
+ language = parts . pop ( ) . toLowerCase ( ) ;
1759
+ // Here we accept also locales if they don't specify a language,
1760
+ // e.g. just 'Arab' or 'Latn-UK', as we can just use the default
1761
+ // setup for the script later.
1762
+ if ( parts . length && parts [ 0 ] . length === 4 )
1763
+ script = ucFirst ( parts [ 0 ] . pop ( ) ) ;
1764
+ // This can be at second position if there's no script specified
1765
+ // e.g. 'de-DE'
1766
+ // We don't use the territory so far!
1767
+ if ( parts . length && parts [ 0 ] . length === 2 )
1768
+ territory = parts . pop ( ) . toUpperCase ( ) ;
1769
+
1770
+ // Ideally locale would contain {language}-{script}-{region}
1771
+ // as in ISO e.g. en-Latn-us, so we could make very elaborate decisions.
1772
+ // In this application, however, {scrip}` is more generic than {language}
1773
+ // I.e. we will fallback to the more general typography settings of a
1774
+ // {script} if specific {language} (similar {region}) are not available.
1775
+ // The hierarchy should be {script} > {language} > {region}.
1776
+ // It is however very possible that we get a {language} without the
1777
+ // {script}. There are defaullt scripts for languages in the Unicode
1778
+ // Common Locale Data Repository (CLDR) which we can use to determine
1779
+ // the default script when we only get a language.
1780
+ //
1781
+ // https://github.com/unicode-org/cldr-json/
1782
+ //
1783
+ // Here's an example of existing locale variants for az (Azerbaijani):
1784
+ // "az", "az-Arab", "az-Arab-IQ", "az-Arab-TR", "az-Cyrl","az-Latn"
1785
+ // from cldr-json/cldr-json/cldr-core/availableLocales.json
1786
+ // it has Arab, Cyrl and Latn as possible scripts!
1787
+ //
1788
+ // We can find in cldr-json/cldr-json/cldr-core/supplemental/languageData.json:
1789
+ // (see also https://www.unicode.org/reports/tr35/tr35-info.html#Supplemental_Language_Data)
1790
+ // [...], "az": {
1791
+ // "_territories": ["AZ"],
1792
+ // "_scripts": ["Arab", "Cyrl", "Latn"]
1793
+ // },
1794
+ // So, if we don't get an explicit script for a language, we pick
1795
+ // the first of "_scripts" in there as the default script for that
1796
+ // language.
1797
+ //
1798
+ // Since we start with en-Latn and that is all we have right now,
1799
+ // that typeSpec will be elevated to be the default of everything.
1800
+
1801
+ // For now only using a small excerpt from the CLDR mentioned above.
1802
+ const languageToScript = {
1803
+ 'en' : 'Latn'
1804
+ , 'de' : 'Latn'
1805
+ , 'az' : 'Arab' // as per the example above
1806
+ } ;
1807
+ if ( ! script && ( language in languageToScript ) )
1808
+ script = languageToScript [ language ] ;
1809
+
1810
+ return [ script , language , territory ] ;
1811
+ }
1812
+
1813
+ function selectTypeSpecByLanguage ( typeSpecI18N , localeStr ) {
1814
+ // this is a stub
1815
+ // next, .de will be added
1816
+ // other scripts like cyrillic, greek, all the other
1817
+ //
1818
+ // initially we'll only have a different config for "de" (German)
1819
+ // but that will change!
1820
+ // We'll also have differences for the scripts (Latn, Arab, Cyrl. Grek)
1821
+ // likeley a go-to for the default script of the lang then the specific
1822
+ // settings for the lanf writtten in that script. Our current English
1823
+ // setting would become the default for all of Latn. German will, so
1824
+ // far. have only less minimal column width than english, because it
1825
+ // has longer words.
1826
+
1827
+
1828
+ // So far only columnConfig is internationalized, hence it makes sense
1829
+ // to return it's configLanguageCode. Later, probably the most specific
1830
+ // code of the different typeSpec sections should be returned.
1831
+ const [ configLocale , columnConfig ] = getFromI18NConfig ( typeSpecI18N . columnConfigI18N , parseLocale ( localeStr ) )
1832
+ return [ configLocale , {
1833
+ columnConfig
1834
+ , cssKeyframeFixes : typeSpecI18N . cssKeyframeFixes
1835
+ , justificationSpecs : typeSpecI18N . justificationSpecs
1836
+ , wdthJustificationSpecs : typeSpecI18N . wdthJustificationSpecs
1837
+ } ] ;
1838
+ }
1728
1839
1729
1840
// TODO: I think this should eventually become a Controller class where
1730
1841
// state is managed more explicitly, I'm not sure yet, however of the full
@@ -1739,12 +1850,8 @@ export function main(
1739
1850
, WikipediaArticleURLWidget= null
1740
1851
, defaults= { }
1741
1852
} ,
1742
- { /* typeSpec */
1743
- columnConfig : columnConfigI18N
1744
- , cssKeyframeFixes
1745
- , justificationSpecs
1746
- , wdthJustificationSpecs
1747
- }
1853
+ typeSpecI18N ,
1854
+ massageConfigurations = { }
1748
1855
) {
1749
1856
1750
1857
let contentDocument = contentWindow . document
@@ -1753,8 +1860,6 @@ export function main(
1753
1860
: contentWindow
1754
1861
, widgetHostDocument = widgetHostWindow . document
1755
1862
, widgetInParent = contentWindow !== widgetHostWindow
1756
- // i18n is a stub
1757
- , columnConfig = columnConfigI18N . en
1758
1863
;
1759
1864
1760
1865
if ( widgetInParent ) {
@@ -1780,11 +1885,28 @@ export function main(
1780
1885
]
1781
1886
, toggleUserSettingsWidget = null
1782
1887
, runion01Elem = null
1888
+ , columnConfig = null
1889
+ , cssKeyframeFixes = null
1890
+ , justificationSpecs = null
1891
+ , wdthJustificationSpecs = null
1892
+ // not used so far
1893
+ , configLocale = null
1783
1894
;
1784
1895
1896
+ let initContent = ( contentLanguageCode ) => {
1897
+ let rawColumnConfig = null ;
1898
+ [ configLocale , {
1899
+ columnConfig : rawColumnConfig
1900
+ , cssKeyframeFixes
1901
+ , justificationSpecs
1902
+ , wdthJustificationSpecs
1903
+ } ] = selectTypeSpecByLanguage ( typeSpecI18N , contentLanguageCode ) ;
1785
1904
1905
+ columnConfig = massageConfigurations ?. columnConfig
1906
+ ? massageConfigurations . columnConfig ( rawColumnConfig )
1907
+ : rawColumnConfig
1786
1908
1787
- let initContent = ( ) => {
1909
+ console . log ( 'contentLanguageCode:' , contentLanguageCode , 'configLocale;' , configLocale . map ( e => e . toString ( ) ) . join ( '-' ) ) ;
1788
1910
let userSettingsWidgetContainer = widgetHostDocument . querySelector ( userSettingsWidgetSelector ) ;
1789
1911
if ( ! userSettingsWidgetContainer ) {
1790
1912
console . log ( 'Demo is disabled: no userSettingsWidgetContainer.' ) ;
@@ -1970,15 +2092,16 @@ export function main(
1970
2092
. checked )
1971
2093
justificationController . run ( ) ;
1972
2094
}
1973
- , updateAfterChangedContent = ( ) => {
1974
- initContent ( ) ;
2095
+ , updateAfterChangedContent = ( contentLanguage ) => {
2096
+ initContent ( contentLanguage ) ;
1975
2097
// This will most likely be executed by the USER_SETTINGS_EVENT handler
1976
2098
// so here's a way to cancel this fail-safe initial call.
1977
2099
scheduleUpdateViewport ( ) ;
1978
2100
}
1979
2101
;
1980
2102
1981
- updateAfterChangedContent ( ) ;
2103
+ // FIXME: remove hard coded default, should be done differently.
2104
+ updateAfterChangedContent ( 'en' ) ;
1982
2105
// FIXME: resize is currently only interesting when the width of
1983
2106
// the page changes, height can change more often (open the debugger,
1984
2107
// OSsses may change height to make room for the main toolbar when in
0 commit comments