(Redirected from Language support)Jump to navigation Jump to search
Improving Inkscape support for internationalized/multi-lingual SVG
There are two distinct language settings:
- the user's preferred language(s) (affects systemLanguage conditional test)
- declaring the document/element language (xml:lang); for SVG 2, this would be used as a conditional switch for <title> and <desc>
systemLanguage & conditional tests
- The systemLanguage attribute is used to only show certain content if it matches the user's preferred language, usually within a `<switch>` element. In a browser, the user's preferred languages are the same as those sent in HTTP headers.
- Support for displaying conditional SVG is implemented within conditions.cpp, which uses SPDocument.getLanguage() (document.cpp) to find the user's preferred language (as set in the preferences dialog)
- BUG: If the user's preference setting is "System Default" (the default), it does not match the actual language code! See Bug #1249423
- possible bug: According to the specs, the user's preferred language shouldn't be a document property, it should be a UI property. However, if Inkscape in the future implements ways to create <switch> elements, you would definitely want to swap between languages on a document basic (instead of resetting their UI settings and restarting Inkscape).
- Potential enhancements:
- The user should be able to set alternate languages in preferences, similar to how browsers set multiple values for the HTTP Accept-Language header (and use the same values for <switch>).
- The user should be able to temporarily swap the preferred language for any document view, to see how the graphic looks like for others.
- If the conditional tests all fail within a <switch>, the user could be prompted to select which language they prefer.
- No UI support currently for creating <switch>, this would all be enhancement
- Best use case would be within individual <text> elements, to switch between languages
- would need a way to swap the canvas view to show the different languages (e.g., temporarily swap the user preferred language for that document)
- would need a way to specify which text should be used as default, and then to store the language information (as xml:lang probably). In the SVG markup, the only way to create a default is to give it as the last element in a <switch>, and don't give it a systemLanguage attribute
- The xml:lang attribute defines the language of text content (visible text or alternative text). It is used in advanced text layout, by screen readers, and by web translation tools.
- For reading existing files, this is relevant for
- passing information to OS Accessibility APIs
- rendering text in certain scripts where the Unicode characters map to different glyphs depending on the language
- Would need some typography experts to confirm that there is already support in underlying text layout libraries (HarfBuzz/Pango), and what info needs to be forwarded to them to get the correct rendering.
- The code for figuring out the current language is already used in CSS to match the :lang() pseudo-selector (cr-sel-eng.c). If there are no bugs there, it can hopefully be generalized for finding out the language code and passing it to text layout.
- There should be a document-level property that can be set (e.g., xml:lang attribute on the <svg> element) see Bug #170340
- Currently, there is a language field in the document metadata, but this is not used for xml:lang.
- By default, the document language should be the user's preferred language at the time the document is created, but it should be easy to change.
- Ideally, you should be able to set xml:lang on individual elements or groups, in order to define multi-lingual documents.
- For text elements, this could be in the font & text dialog, but more generally it would be in object properties
- However, you should also be able to set language on a <tspan>, so that would mean allowing the user to select some text and then assign a language value.
- Would want to have a "use document language" checkbox (with the current document language setting clearly stated); if unchecked, you would then have a drop-down list/text box to set a different language for this element. Technically, this shouldn't be "document" language, but "parent element" language (since you could set language on groups or similar); not sure what a better wording would be.
Making use of language for added features:
- Once Inkscape is able to keep track of the document language, and the user is able to set the document language, then it would be possible to implement spelling/grammar checking or other language-based features.
- For spellcheck, there is even a functionality in GTK: see http://wiki.inkscape.org/wiki/index.php/SpellCheckForTextNodes. text-edit.cpp has a TODO to use a computed value of xml:lang in gtkspell_set_language().
Multi-lingual accessible text:
- For SVG 2 multi-lingual title/desc, you would need a way to
- add additional title/desc in the object properties dialog,
- set the language for each (this should be *required* for having multiple title/desc elements) and
- specify which one is the default
- For title/desc, the default *would* have a lang attribute (note, SVG 2 spec currently uses `lang` not `xml:lang`), and would be the *first* such child element in the DOM.