Help me create an extension

Discussions about using 3rd party extension with OpenOffice.org
Post Reply
color
Posts: 2
Joined: Wed Nov 14, 2018 10:32 am

Help me create an extension

Post by color »

I'm new here and never created an extension before and don't know where to start or how to do it.

I often read old swedish text sometimes from the 1800-1930. But I want to "translate" them to newer swedish. Can someone help me to create an extension that can help me translate words automatically? I got a small list and It needs to be longer. I have translated word my word with the "Ctrl+F" but It takes so mutch time.

For example it was used the word "gingo" before but we now say "gick" and "sven" is nowdays "gosse". Is there a way to put rules so It only change those words so they don't do "svensk" to "gossesk". Also so It can change to letter/case sensitive like if its a big letter in the beginning it translate to a big letter.

I need to be able to put in new words and what they should be.
OpenOffice 3.1 on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Help me create an extension

Post by Villeroy »

Are you a computer scientist, a programmer and a linguist? Then go ahead, hire at one of the big IT companies, get rich and famous.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Help me create an extension

Post by Villeroy »

https://extensions.libreoffice.org/exte ... eno-german is a stenograhic system for German language. Its implementation is just a huge file of replacements for the auto-correct featue. It took months if not years to build that file.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Help me create an extension

Post by RoryOF »

This is an exceedingly complex problem for the beginner. You will need to learn an entire new language (one of the computer languages OpenOffice understands), and write the rules for your translation, then apply these in the chosen computer language, using its correct syntax.

It will be easier for you to become completely familiar with the old forms of the language and let your brain do the translation, manually typing the correct output if that is the output you require.

There may already be some computer translation programs you could adapt to your specific need - a quick search should find these.

I know of one very experienced programmer who has spent many years working on a translation program for a particular language, in which he is fluent from birth into another language, in which he is also fluent from birth; he does not feel he will have this project finished in his lifetime.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Help me create an extension

Post by RoryOF »

OmegaT translation program might help.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Help me create an extension

Post by JeJe »

If there are no grammatical issues and its just straight replacement of a list of words with their translated word then this is a simple task. You'll need to loop through all the words in your document instead but for a simple list of words with spaces and no punctuation:

Code: Select all

	REM  *****  BASIC  *****
	dim words as new collection

Sub Main
	dim wds() as string

	words.add "gick","gingo"
	words.add "gosse","sven"

	st =  "gingo Sven svensk"
	wds = split(st," ") 
	
	for i = 0 to ubound(wds)

		replacement  =GetWd(words,wds(i))

		if len(replacement) <>0 then 'if word found then
			leftchar = left(wds(i),1) 'if leftmost character uppercase change it
			if ucase(leftchar) = leftchar then
				leftchar= left(replacement,1)
				mid(replacement,1,1)= ucase(leftchar)
			end if

			wds(i) = replacement
		end if
	next

	st = join(wds," ")
	msgbox st
End Sub

function GetWd(c as collection,key as string) as string
	on error resume next
	GetWd = c.item(key)
end function


Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Help me create an extension

Post by JeJe »

Something like this:

NOTE: There may be problems with OO's gotoNextWord function...

Code: Select all



	REM  *****  BASIC  *****
	dim words as new collection

	'tested with the following in a writer document. I added END as it won't work for the last word.
	'gingo Sven svensk END"


Sub Main


	words.add "gick","gingo" 'add words to a collection
	words.add "gosse","sven"

	oText = thisComponent.getText
	oCursor = oText.createTextCursorByRange(oText.getStart)

	thiscomponent.lockcontrollers
	on error goto hr

	do
		oCursor.collapsetoend
		res=oCursor.gotoNextWord(true)
		if res = false then exit do
		wd= oCursor.string
		replacement = GetWd(words,wd)

		if len(replacement) = 0 then if not found try one letter shorter
			oCursor.goleft(1,true)
			wd= oCursor.string
			replacement = GetWd(words,wd)
			if len(replacement) = 0 then oCursor.goright(1,true)
		end if

		if len(replacement) <>0 then 'if found
			leftchar = left(wd,1) 'if leftmost character uppercase change it
			if ucase(leftchar) = leftchar then
				leftchar= left(replacement,1)
				mid(replacement,1,1)= ucase(leftchar)
			end if

			oCursor.string = replacement
		end if



	loop


hr:

	thiscomponent.unlockcontrollers

End Sub

function GetWd(c as collection,key as string) as string
	on error resume next
	GetWd = c.item(key)
end function


Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
color
Posts: 2
Joined: Wed Nov 14, 2018 10:32 am

Re: Help me create an extension

Post by color »

Jeje, It has changed so little more than the words in text it is still very similar. They do write in a little bit different way but still many people do this today but with "modern" words, so there will not be a lot of grammatical issues. Most of the time its the spelling like "gifva" is spelled "giva" today. Its kind off straight forward.

"De ryckte upp unga lövträd med roten och vinkade med dem till drottningen, och då de gingo in i sina stenstugor, där hustrun satt i bekymmer och längtan, skrattade de och sade:"

will be:

"De ryckte upp unga lövträd med roten och vinkade med dem till drottningen, och då de gick in i sina stenstugor, där hustrun satt i bekymmer och längtan, skrattade de och sa:"

so there is not alot to change.

If I use for exempel that you wrote

Code: Select all

words.add "gick","gingo" 'add words to a collection
is it the full word gingo it change to gick or will it change a word that has gingo it like gingolo to gicklo? Also, will it change the first letter if its a big letter to a big letter or a lower case?

Also. can I use notepad++ and how should I save the file as for format? And is it just to "run" in openoffice or how does it work?
I am still a beginner but I'm so happy for all help, thank you. :)
OpenOffice 3.1 on Windows 10
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Help me create an extension

Post by JeJe »

The method I've posted is going through the words of a document from start to end and changing them. Unfortunately the OO function to find words and move to the next word aren't very good. If you try it and it doesn't do exactly what you want you'll have to tweak it until it does.

There are various ways - if you look up Regular Expressions - that's another way of replacing words. One I can't help you with - as I don't use them.

If someone posts some code you have to try it out - before posting again. Putting in a module and pressing F5 should take less time than it took to write out your post.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
esperantisto
Volunteer
Posts: 578
Joined: Mon Oct 08, 2007 1:31 am

Re: Help me create an extension

Post by esperantisto »

OOoFBTools has a feature of so called yofication of Russian texts, i. e. replacing certain words spelled with е with their counterparts spelled with ё. It works as as simple mass find-and-replace. So, you might want to
a) look into the code and build your own extension; or (well, seems simpler to me)
b) install the extension, find yo.txt in the user profile, replace its contents and use the yofication feature. The format is simple:

Code: Select all

oldword|newword
(note the entry count in the first line in the file).
AOO 4.2.0 (of 2015) / LO 7.x / Win 7 / openSUSE Linux Leap 15.4 (64-bit)
Post Reply