From 2ad084b362b71e646785b7a86e0ea21827e9d844 Mon Sep 17 00:00:00 2001 From: denizsincar29 <46639905+denizsincar29@users.noreply.github.com> Date: Sun, 27 Feb 2022 16:33:58 +0300 Subject: [PATCH] now you can update translations great. now lets think you have a big script that you translated to german. and you added a new string. what will you do? you will say that you will update it in tsv file in notepad. but what if you make an accident there? from now on, when you extract a script, you can extract an updated script into the same tsv. for instance you have a german translated tsv file for a script. you add a new string in function _(), and you want to update tsv file. the existing german translations will not be lost and you will get new strings at the end of tsv file! --- Extract.au3 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Extract.au3 b/Extract.au3 index 2dca59e..0099925 100644 --- a/Extract.au3 +++ b/Extract.au3 @@ -8,18 +8,19 @@ Global Const $ECI = @ScriptDir & '\eci\build\eci.exe' Main() Func Main() - Local $sScript = FileOpenDialog("Select Script", @WorkingDir, 'AutoIt Script (*.au3)', $FD_FILEMUSTEXIST) + Global $sScript = FileOpenDialog("Select Script", @WorkingDir, 'AutoIt Script (*.au3)', $FD_FILEMUSTEXIST) If @error Then Return Local $aStrings = ExtractStrings($sScript) If $aStrings[0] = 1 And $aStrings[1] = "" Then MsgBox($MB_ICONWARNING, "No translatable strings", "There were no translatable strings found in your script, please make sure you use the underscore function to wrap your translatable strings!") Return EndIf - + Global $sTableFile = FileSaveDialog("Save translation table", @WorkingDir, 'Tab Separated Values (*.tsv)|All (*.*)', 0, 'translations.tsv') +;i moved local sTablefile up because we must know what file we are updating. Local $sTable = GenerateTranslationTable($aStrings) - Local $sTableFile = FileSaveDialog("Save translation table", @WorkingDir, 'Tab Separated Values (*.tsv)|All (*.*)', 0, 'translations.tsv') If @error Then Return - Local $hTableFile = FileOpen($sTableFile, $FO_OVERWRITE + $FO_UTF8_NOBOM) + ;removed $fo_overwrite because maybe we want to update the translation table with new strings. + Local $hTableFile = FileOpen($sTableFile, $FO_UTF8_NOBOM+$FO_APPEND) FileWrite($hTableFile, $sTable) FileClose($hTableFile) EndFunc @@ -35,10 +36,15 @@ Func ExtractStrings($sFile) EndFunc Func GenerateTranslationTable(ByRef $aStrings) + local $ss + if fileexists($stablefile) then + $ss=fileread($stablefile) ;this is made to update a translation file with not existing translated strings that were added to the translated program later +endif Local $sTable For $i = 1 To $aStrings[0] - If StringIsSpace($aStrings[$i]) Or StringLen($aStrings[$i]) = 0 Then ContinueLoop + ;checking if a translation table have this string, as well as checking if a line is space or stringlen=0 + If StringIsSpace($aStrings[$i]) Or StringLen($aStrings[$i]) = 0 or stringinstr($ss,$aStrings[$i]) Then ContinueLoop $sTable &= $aStrings[$i] & @TAB & $aStrings[$i] & @LF - Next + Next Return $sTable EndFunc