Skip to content

Instantly share code, notes, and snippets.

@xperseguers
Last active December 22, 2023 09:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xperseguers/2ce07ad842e0b953cc70d51a87d3d5fb to your computer and use it in GitHub Desktop.
Save xperseguers/2ce07ad842e0b953cc70d51a87d3d5fb to your computer and use it in GitHub Desktop.
Migrate from Pootle to Crowdin

Migrate your project from Pootle to Crowdin

Step 1: Choose extensions to migrate

I have a few extensions of mine on Pootle and I decided to migrate those:

  • cloudflare
  • direct_mail_userfunc
  • file_list
  • ig_ldap_sso_auth
  • image_autoresize
  • restdoc

First step is to get the project set up on Crowdin. For this, you need to get in contact with the team in the TYPO3 slack channel cig-crowdin-localization with the following information:

  1. The list of extensions you own and want to migrate to Crowdin
  2. Information that your extension is already available on the previous translation server
  3. Your email address for an invitation to Crowdin, so you will get the correct role for your project.

The team will set up projects for those extensions, and you will get invitation notifications from Crowdin sent by email.

Step 2: Check projects in Crowdin

The invitation emails just invite you to log in to Crowdin: https://crowdin.com/profile

Check that you see all of your projects and proceed to step 3.

Step 3: Create an API token

On Crowdin, click your avatar top right and choose Settings within the context menu. Then move to tab API and click the button "New Token". Choose following scopes:

  • Projects (List, Get, Create, Edit)
  • Source files & strings
  • Translations

Give a name for that token (e.g., "Pootle migration") and be sure to copy and save the generated token as you won't be able to see it again.

Step 4: Set up integration from your Git repository

Please follow instructions from https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/Localization/TranslationServer/Crowdin/ExtensionIntegration.html#crowdin-extension-integration

Goal is to import your source files (English) and set up the link so that your project on Crowdin gets automatically updated whenever you update the source localization files.

Useful info

A few steps in the official instructions are not 100% clear:

  • Set Up Integration > Source and translation files mode
  • When setting up (GitHub integration), you may leave the checkbox "One-time translation import after the branch is connected" ticket. Just adapt the Configuration File Default Name at the very end to .crowdin.yaml

Step 5: Import content from Pootle

In order not to loose all the work translators did in the past, you should import existing files and translations from Pootle.

Example with the project "cloudflare".

This may be done manually, but I will use the Console Client (CLI) for Crowdin. Install as described on: https://developer.crowdin.com/cli-tool/

Run the fetch-packages.sh script with

  • parameter 1: the extension key
  • parameter 2: the path to your extension project on disk

E.g.,

./fetch-packages.sh cloudflare ~/Projects/TYPO3/cloudflare

The script will fetch all existing translations for you, prepare the corresponding upload configuration file and give you last instructions on how to finalize the import.

#!/bin/bash
EXTENSION=$1
TARGET=$2
if (($# < 2)); then
echo "Usage: $0 <extension-key> <path/to/extension-project>" >&2
exit 1
fi
if [ ! -d $TARGET ]; then
echo "$TARGET is not a valid project directory" >&2
exit 2
fi
if [ $(basename $TARGET) != $EXTENSION ]; then
echo "$TARGET does not seem to be the project directory for extension $EXTENSION." >&2
echo "We expect it to end with '$EXTENSION'." >&2
exit 3
fi
pushd $TARGET >/dev/null
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ $? -ne 0 ]; then
echo "$TARGET is not a git repository" >&2
exit 4
fi
rm -rf __crowdin__/$BRANCH/Resources/Private/
mkdir -p __crowdin__/$BRANCH/Resources/Private/
mkdir __crowdin__/$EXTENSION
cp -r Resources/Private/Language __crowdin__/$BRANCH/Resources/Private/
popd >/dev/null
XML=https://localize.typo3.org/xliff/${EXTENSION:0:1}/${EXTENSION:1:1}/${EXTENSION}-l10n/${EXTENSION}-l10n.xml
LANGUAGES=$(curl -s $XML -o - | grep "language=" | sed -E 's/^.*language="([^"]+)".*/\1/' | grep -v "dk")
for LANG in $LANGUAGES; do
echo "Fetching localization for $LANG"
URL=https://localize.typo3.org/xliff/${EXTENSION:0:1}/${EXTENSION:1:1}/${EXTENSION}-l10n/${EXTENSION}-l10n-${LANG}.zip
FILE=${LANG}.zip
rm -f $FILE
curl $URL -o $FILE
unzip $FILE -d $TARGET/__crowdin__
rm -f $FILE
echo
done
cp -r $TARGET/__crowdin__/$EXTENSION/* $TARGET/__crowdin__/$BRANCH/
rm -rf $TARGET/__crowdin__/$EXTENSION
echo "Creating configuration for uploading XLIFF to Crowdin"
cat <<EOT > $TARGET/__crowdin__/upload.yml
"project_id": "project-id"
"api_token": "personal-access-token"
"base_path": "."
"base_url": "https://api.crowdin.com"
"preserve_hierarchy": true
"files": [
{
"source": "$BRANCH/**/local*.xlf",
"translation": "/%original_path%/%two_letters_code%.%original_file_name%"
}
]
EOT
echo
echo "1. Go to $TARGET/__crowdin__"
echo "2. Edit file upload.yml and configure the 'project-id' and your 'personal-access-token'"
echo " Note: the 'project-id' is found on the homepage of your project on Crowdin, top, right below the name of your extension"
echo "3. Run:"
echo
#echo " crowdin upload sources --config ./upload.yml"
echo " crowdin upload translations --config ./upload.yml"
echo
@prathers
Copy link

prathers commented Dec 5, 2022

Cool Xavier!

A suggestion: The right way to get a project up running on Crowdin, is to take contact with the team in the TYPO3 slack channel cig-crowdin-localization as described here:

https://docs.typo3.org/m/typo3/reference-coreapi/11.5/en-us/ApiOverview/Localization/TranslationServer/Crowdin/ExtensionIntegration.html#setup

@xperseguers
Copy link
Author

@prathers done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment