Automatic translation with Plang (OpenAI underneath)

So, I recently had a client setting up a new website, and everything was written in English. The catch? They needed to translate it all into Icelandic. The developers handed over an Excel file with about 350 keywords to translate. Not a massive task, but still enough to be a bit of a time sink if done manually.

Here’s a peek at how the Excel file looked:

Instead of slogging through it by hand, I figured I’d try out Plang to see if I could save everyone some time.

Plang is a programming language that uses OpenAI underneath to translate the developers intent to code

Try it

If you like to try this, then install Plang and get a basic understanding of how Plang works

Getting Started

First off, setting things up is a breeze. Just create a Translate.goal file and open it in your favorite text editor.

Kick things off with the line:

Translate

This is the name of the goal, goal is like a function

Reading the Excel File

Next up, we need to read the Excel file. Here’s how you do it in Plang:

- read file translations.xlsx, sheet:translations, into %translations%

This tells Plang to grab the data from the translations sheet in translations.xlsx and load it into the %translations% variable.

Splitting the List

With 350 keywords, sending everything to the language model in one go might be overkill. To avoid confusion (for the model), we split the list into chunks of 20 items:

- [code] split %translations% with 20 items in them,
     write to %translationsLists%

Now, %translationsLists% contains multiple smaller lists, each with 20 keywords.

Processing the List

Next, we loop through each chunk in %translationsLists% and call TranslateList for each one:

- foreach %translationsLists%, call TranslateList 

This step makes sure each group of keywords gets processed.

Time to Translate

Here’s where the magic happens. We get the language model to translate the keywords into Icelandic:

TranslateList
- [llm] system: Translate the messages to Icelandic, leave key as is
    user: %item%
    scheme:[{key:string, message:string}]
    write to %translated%

After this, %translated% contains the Icelandic translations paired with the original keywords.

Saving the Translations

Finally, we save the translations into a CSV file:

- append %translated% to csv file 'translate.csv'

And that’s it! We’ve got our translations neatly saved in translate.csv.

Wrapping Up

In about five minutes, I put together a script that automates translating a list of keywords. Here’s the full code:

Translate
- read file translations.xlsx, sheet:translations, into %translations%
- [code] split %translations% with 20 items in them,
     write to %translationsLists%
- foreach %translationsLists%, call TranslateList 

TranslateList
- [llm] system: Translate the messages to Icelandic, leave key as is
    user: %item%
    scheme:[{key:string, message:string}]
    write to %translated%
- append %translated% to csv file 'translate.csv'

It’s important to note that even though the heavy lifting is automated, a human still needs to review the translations. They’ll catch the context-specific nuances that the model might miss.

Feel free to tweak this approach for your own projects. Let me know how it works for you!

More Information

If Plang is interesting to you, you should dig a bit deeper:

1 Like

Thanks for sharing. I’ve moved your post to Community and added a project tag. This makes it easy for the community to keep up to date on your project. Thanks!

1 Like

Thanks for that, sorry about the wrong category :blush:

Hi all

I have create a new type of programming language that I call PLang, you can find how to download and get started here v0.1 is out · PLangHQ · Discussion #25 · GitHub

It gives you some very nice benefits, simplifies coding for your, no more syntax errors, makes life easier in implementing and solving business cases.

Here is a simple example of an app that reads csv, ask llm to analyze and writes down results

ProcessCSV

  • read data.csv into %data%
  • [llm] system: Analyse the data from user. The data is from a weather station
    user: %data%
    write to %dataAnalyzed%
  • save %dataAnalyzed% to report.txt

It uses GPT4 underneath to build, it takes you intent and converts an executable code. It is a proper programming language, not GPT4 generating code for your.

Hope you check it out, I know you will enjoy it. There are some other lovely discoveries, the deeper you dig :slight_smile:

Ingi

Cool stuff!

Is the generated code guaranteed to be syntactically consistent?

Yes it is.

I have also gotten the question, since it´s chatgpt, will the code change. The answer is no, you build the code, after that it will always stay the same

1 Like

No problem. I put the original post here too as this one is more helpful, I think?

Good luck!

1 Like