Skip to content

How to translate using vscode

Duke M edited this page Jul 17, 2024 · 54 revisions

Visual Studio Code

vscode is a modern, open-source and free texteditor with tons of extensions, I use these for my translation project: vscode extensions

  • Code Spell Checker - helps with finding typos
  • Code Spell Checker - additional dictionary (needs to be explicitly added after installation, just read the extensions readme)
  • Gitlens - helpful while working with git
  • Markdown All in One - helpful while working with md-files (like this article)
  • Markdown Table - i use this to autoformat the tables in the lexicon (in this wiki)
  • Source Engine Support - for colored code in vdf- and txt-files
  • DeepL for Visual Studio Code - to work with the DeepL API inside vscode

Visual Studio Code has an native UI/UX for git, but you still need to install GIT to use it in conjunction with github.

Working with Github

Forking

You cannot (and shouldn't for easier readability and merging) commit to the main repo.
What you do is create a fork (your own copy) to which you will commit your changes to.
how to fork

Merging

Your codebase can be ahead (you did something) or behind (they did something) the changes in the main repo.

If your fork is behind, fetch and merge ... or just let it be done automatically with this.
If your fork is behind and ahead at the same time, do the same, fetch and merge (and hope for no conflicts). fetch and merge

If your fork is ahead, you can ask at the main repo for integration.
You'll do that through a pull request (abbreviated 'PR') which will - if it's fine - be merged into the main repo by an admin. As long as your PR isn't merged by an admin you can still make commits and they will be automatically included in your current open PR, which means you do not have to close a PR just because there is something missing. how to create a pull request

Continous integration

CI are automatically executed checks on your freshly added stuff to ensure least mistakes possible.

When ci-checks fail

Click on Details, if the script stopped somewhere between the NEW_ACHIEVEMENT_* keys, the achievement-entries are not in sync between 563560_loc_your_language.vdf and reactivedrop_your_language.txt files. Solution: open up the utils folder and execute the translation-sync-tool to sync between these 2 files. It's easy to spot any changes made by the tool if you have a clean working tree (no uncommited changes), if you don't have one, don't forget you can stash away stuff for now and get it back later.
stash

If you do fail

I f***** up hard, my commits are wrong, how can I get back to where I was?
Take a deep breath, cool down, make some copies of your hard work on your harddisk and reset back to the latest point where the main repo is. How?

Enter these 5 commands into your vscode's console:
git remote add upstream https://github.com/ReactiveDrop/reactivedrop_translations
git fetch upstream
git checkout master
git reset --hard upstream/master
git push origin master --force

image

Source: https://stackoverflow.com/questions/9646167/clean-up-a-fork-and-restart-it-from-the-upstream

Translation API

DeepL is a translation service which doesn't cost anything (as long as you aren't translating > 500.000 characters per month).

It translates into the following languages:
Bulgarian, Chinese, Czech, Danish, Dutch, English, Estonian, Finnish, French, German, Greek, Hungarian, Indonesian, Italian, Japanese, Latvian, Lithuanian, Polish, Portuguese, Romanian, Russian, Slovak, Slovenian, Spanish, Swedish, Turkish

You just need an account and an API-Key, you'll find one here after you created your account.
There are for sure other services like DeepL (eg. libretranslate) but I'll use this one as my example here.

Auto-translate using DeepL

The DeepL-extension has its own settings including Api-Key, formality of translation and some more.

Configuring DeepL

Throw your Api Key in there, so DeepL knows it's your account which is asking for translation strings. api key in settings

Search and Replace using Regular Expressions

vscode includes native support for regular expressions, open the find-bar (ctrl+f) and hit the rightmost icon in the search-box.
search-box
Here's a cheat sheet if you want to understand the syntax or want to create your own regex strings.

General instructions

  1. Find your strings using the search-function and an regular expression
  2. Press Ctrl+Shift+L to (multi)select the found string(s) in your editor
  3. Press F1 to open Command Palette, there, select 'DeepL: Translate' (select your preferred language once), press Enter and voilà, your selected text has been translated, ready for proofreading.

Useful examples

Search for recently added strings after a sync by the main repo

Press Ctrl+Shift+F to open the project-wide search and enable regex again (probably filter on *.txt files to ignore vdf-files which do not follow the standard of intending new lines)
Use this ^\t\t in the searchbox and something like this *german* in the box 'files to include' to get all untranslated lines

Some example lines

  • (?<=german": ).*$ finds with lookbehind german": , then any character . in any repetition * and then end of line $
  • (?<= )"(.*?)"(?=,) match any string which is predecessed by a space , and has an Comma , ahead
  • (?<=german": )(?<= )"(.*?)"(?=,) same with german only in its key
  • (?<=german": )(?<=\s)"(.*?)"(?=,) \s for any whitespace char
  • (?<=german": ")(.*?)(?=",) same selection but without quotation marks
  • ^"(?!\[english).*clip search for the word 'clip' in all non-english strings

Remove english lines

  • \s*(?="\[english)(.*?)\n\s* replace with \n (the \s* in the end removes all whitespace chars until hitting the next key)

Remove comments

  • // .*\n replace with nothing

Remove empty lines

  • \n\n replace with \n

Select keys only (for comparisons)

  • ^\s*"(.*?)"

Search strings which don't start with an quotation mark

  • \t([A-Za-z0-9-]+)

Search for incorrect line endings

  • ^\s(?!\/\/)(?!GAME).*(?<!(\{|\}))(?<!")$

Count all translateable lines

Want to find out how much there is to translate?
Search the whole project for files including *english* and excluding *_loc_*.
At the time of writing the result were 13.485 lines :)

  • (?!\s*($|//|\{|\}))(^((?!(<?xml|(.|..)list\]|"lang"|"Language"|"Tokens"|"appid"|"itemid"|english)).)*$)