• Bruce Long's avatar
    Windows Spellcheck: Generic preferred languages can be enabled · 0a3c9b58
    Bruce Long authored
    The browser language settings page allows a user to add preferred
    languages, and only the added languages are candidates for toggling
    on for spellchecking. Several of the accept languages come in both
    regionally specific form (Brazilian Portuguese, "pt-BR" e.g.) and
    generic form (Portuguese, "pt" e.g.). However, the current logic in the
    the SpellcheckService class that maps accept language tags to more
    complete BCP47 tags specifying Windows spellcheck dictionaries does
    not map the platform dictionary name to the generic name if an exact
    match is already found. For example, "pt-BR" gets mapped to its exact
    match "pt-BR", but not to "pt". Since there is no Hunspell support for
    generic "pt", you cannot enable generic Portuguese for spellchecking.
    
    A more insidious issue is seen with Italian. If you install the
    Italian (Italy) Windows language pack, you get dictionary support
    for "it-IT" and "it-CH" (Italian as spoken in Italy and Switzerland
    respectively). Since there is an exact match with the "it-IT" accept
    language tag, generic "it" does not get mapped. But since generic "it"
    does have Hunspell support, the hybrid spellcheck fallback logic will
    kick in here. A user can enable generic Italian for spellcheck but in
    fact Hunspell will be used, even with the Italian Windows language
    pack in place.
    
    The fix is to add an entry to the dictionary map for the generic
    language subtag if a regionally specific platform spellcheck dictionary
    is available, and pass the generic subtag to the platform API when
    creating a Windows spellchecker. The platform API is smart enough to
    recognize the primary language associated with a language pack, so
    passing the "pt" subtag will in fact create the "pt-BR" spellchecker.
    
    Note this fix only works when the Windows platform spellchecking
    feature is enabled. If using Hunspell exclusively, you still can't
    toggle generic languages unless they can be mapped to an available
    Hunspell dictionary
    
    Bug: 1105610
    Change-Id: Ib995289a55ed8c8c51bf83e3a1ca4118a07814c8
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2310804Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
    Commit-Queue: Bruce Long <brlong@microsoft.com>
    Cr-Commit-Position: refs/heads/master@{#791808}
    0a3c9b58
spellcheck_service_browsertest.cc 32.4 KB