Skip to content
Advertisement

Google Translate Documents php text

I’d like to run thousands of php language keys through Google Translate Documents on https://translate.google.com. The text looks like this:

$lang['activate_deactivate'] = "Activate / Deactivate";
$lang['invalid_username'] = "Invalid username";
$lang['you_must_enter_username'] = "You must enter username";
$lang['invalid_user_name'] = "Invalid username";
$lang['user_deactivated'] = "User has been deactivated";
$lang['user_not_deactivated'] = "User could not be deactivated";

However I don’t want to translate anything between [ and ]. So far I’ve tried wrapping it in span notranslate tags, capitalizing every word but neither of those worked.

An idea I do have is somehow adding an uncommon character such as █ after every letter between [ and ] then just removing all after the translation, I’m not sure how to perform that with regex. “(?<=[).*?(?=])” will find the text I need but I’m not sure how to replace it to insert the character after each letter.

Or if anyone has any better ideas, I’d love to hear them. Thanks.

Advertisement

Answer

Using Notepad++ you might use:

(?:[|G(?!^))K[^][](?=[^][]*])

The pattern matches:

  • (?: Non capture group
    • [ Match [
    • | Or
    • G(?!^) Assert the current position at the end of the previous match, but not at the start of the string to get consecutive separate matches
  • ) Close non capture group
  • K Forget what is matched until now
  • [^][] Match a single char other than [ and ]
  • (?=[^][]*]) Assert a closing ] to the right

Replace with the full match followed by the character that you want $0█

See a regex demo.

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement