How to create an exportable keyboard input scheme?

I want to create some sort of install-able module that makes LibreWriter automatically replace typed characters with custom characters elsewhere in the unicode range (for UTF-8 encoded text).

So, let’s say that whenever I type “zhe”, librewriter changes “zhe” →

If you’re curious about why I want to do it this way, it’s because I’m a conlanger, and I essentially want to create my own input encoding for my own constructed language font, much the same way Japanese and Chinese creates input encodings for thousands of characters on a standard keyboard.

But I want to create something that can be activated/turned on or off, because obviously, not all my writing will be done in this conlang. And I don’t want to have to create manual substitution inside the editor each time I open a document for this purpose. I also want to be able to share the module/encoding/thingie with other conlangers, so that they can type in my conlang if they want.

I’m sorry to be asking like this, but this is such a niche use case that google and duckduckgo/other search engines are pretty much useless to help. And I don’t know enough about the various terms to know if this is even how this sort of thing is done. So really, any information you can give to help me in the right direction, would be greatly appreciated.

Thank you for your time.

1 Like

Tools → AutoCorrect → AutoCorrect Options… tab Replace, add your replacement entry and hit New. Note that replacements are assigned to a specific language. If it should be for all languages then switch language to [All] first, first entry in that listbox. The replacements are stored in your user profile’s autocorr/ directory, one file per language/locale.

How would I add my own custom conlang to that list?

It probably does not have a IANA assigned BCP 47 language tag, see Codes for constructed languages - Wikipedia , otherwise it would be easy and you could just format a character using that code entered in the Language field of the Font dialog. The language name stated in the status bar then would also appear in the AutoCorrect list.

If not, the easiest would be to use a “reserved for local use” ISO 639-2 code like qcl (all qaa to qtz are reserved for local use, the cl here just for “constructed language”). But such code is completely unspecific and if you plan to share documents is not the proper way to go, as it wouldn’t be local anymore and could clash with other uses.

Rather think about an art-x-privuse tag, where art is the assigned code for “artificial” and x-privuse a private use subtag, where privuse can be any combination of a-z characters up to 8 characters. You should also consult ConLang Code Registry to make sure it doesn’t clash with an already existing definition. Note that the qaa to qtz codes listed there should not be used for the reasons I gave.

LibreOffice does not allow entering arbitrary private-use tags in the character font language field to prevent shooting oneself into the foot… The way to go then would be to edit a stored empty document or template with any language and replace the style’s attribution, i.e. in its content.xml change

<style:text-properties fo:language="en" fo:country="US"/>

(if language was English (USA)) to

<style:text-properties style:rfc-language-tag="art-x-yourconl"/>

and freshen the zip’s content.xml with the change and then reload the document in Writer. The language would then be shown as art (Private-Use=yourconl) {art-x-yourconl} and also be available in AutoCorrect. You just needed to load the empty template to create content attributed with art-x-yourconl, otherwise the language won’t be available.

I or someone else here could help you with that content.xml change if you don’t know how, once you made up your mind what actually to use for yourconl.

4 Likes

Ah! Thank you, erAck. I was able to save the file in .fodt format, and then use notepad++ to find and change the relevant xml fields. Your answer was super helpful, and I now have the proper language added, thank you!

Having said that, I take it that if I want to share my input scheme, I’ll essentially need to share the modified template file, yes? There’s no other way to add the language than to essentially become a contributor to the libreoffice project, right? Do you mind if I ask about how I go about doing that? Sorry for the trouble. ^^;

But in the meantime, your answer here will suffice perfectly. Thank you very much! :smiley:

Yes. And the resulting user profile’s autocorr/acor_art-x-yourconl.dat of course.

Adding the language permanently to the language list? I’d refrain from that. The list is already cluttered enough. I’m rather thinking of opening the Language edit field to accept art-x-… and art-Latn-x-… (with Latn being any valid script code) private-use tags so any constructed language can be assigned. Also, placing an acor_*.dat with a valid language tag into the autocorr/ directory could add the language tag to the list, so the template kludge wouldn’t be needed anymore.

I filed tdf#150370 and tdf#150371 for this.

Apart from that, if you are interested in contributing to LibreOffice in any way please see Get Involved or https://whatcanidoforlibreoffice.org/ ;-)

Update 2022-09-01T11:42+02:00:
Both, tdf#150370 accepting art-... private-use tags in the language list combo box and tdf#150371 creating an additional language list entry by dropping an acor_*.dat with a valid language tag in the autocorr/ directory are implemented for LibreOffice 7.5.

Thanks for sharing this. It was very useful. But there is no .dat file in my user profile.

I am not sure how to share my files because autocorr folder is missing. But everything else works as expected.

The user profile’s autocorr directory doesn’t exist as long as you didn’t add any user-defined AutoCorrect entries as lined out in the answer above. You can create the directory manually to place a acor_*.dat file that you obtained elsewhere, or to touch/create one for the new feature in LibreOffice 7.5.

Even after adding a few entries to that language list, the folder autocorr was still missing from user profile. I created that folder manually but no file is being placed here even if I can see the custom language and entries in tools - Autocorrect - options. I have no idea where the replacement entries are being saved. :thinking:

I think you’re mixing things up. Merely adding a language tag to the language list does not create any AutoCorrect entry thus the autocorr directory isn’t created either. Only actually adding a replacement under AutoCorrect will create it and a corresponding acor_*.dat file.

Thanks for your guidance. It is working as expected. (The file was created after resetting the user profile.)