- Считывает заголовки и пункты;
- Подгрузка не законченного перевода или создание нового файла перевода;
- Работа с многострочным текстом;
- Игнорирует лишние пустые строки в .ini файле;
- Считывает значения в массив через RegEx;
- Видимый процесс загрузки и сохранения файлов;
- Всякого рода предупреждения.
Использование:
Запускаем, жмём Open original, выбираем .ini файл, считаются все его секции\переменные\значения, будет предложено подключить файл перевода или отказаться от него. Выбираем в списке слева имя переменной, в поле сверху будет видно его значение. Ниже пишем перевод значения. Перевод сохраняется при выборе следующей переменной в списке. Сохраняем перевод по кнопке SaveAs в отдельный файл, его можно будет подключить к оригинальному .ini в любое время.
Code: Select all
;====INTERFACE
;Wrote by Willy-Fox
MainWindow:
Gui, Color, EFEFEF
Gui, Add, GroupBox, x12 y69 w820 h420 ,
Gui, Add, Button, x22 y19 w100 h30 vOpenOrig gOpenOrig, Open original ;Open a source file to pick a keys to translate
Gui, Add, Button, x132 y19 w100 h30 vOpenTrans gOpenTrans Disabled, Open translation ;Open a mid-translated file to get already translated keys before
Gui, Add, Button, x722 y19 w100 h30 vSave gSave Disabled, Save as...
Gui, Add, ListBox, x32 y99 w130 h380 vEntriesListBox gSelectEntry AltSubmit, ;Keys list
Gui, Add, Edit, x182 y119 w640 h150 vEntry ReadOnly, ;Shows a raw text
Gui, Add, Edit, x182 y309 w640 h160 vTranslated, ;Field to translate the text
Gui, Add, Text, x182 y99 w140 h20 , Input text
Gui, Add, Text, x182 y289 w150 h20 , Output text
Gui, Font, s14 Bold
Gui, Add, Text, x262 y279 w600 h30 vLoading,
Gui, Show, Center h512 w851, Manual AHK ini translator
Return
;====OPEN A SOURCE file to pick a keys to translate
OpenOrig:
FileSelectFile, PickedFile, 3, %A_ScriptDir%,, Language files (*.ini)
if ErrorLevel ;Return if calcel
{
Return
}
GuiControl, Disable, OpenOrig ;Disables Open original button
CategoryTotal := 0
EntriesTotal := 0
BlockFound := False
Loop, Read, %PickedFile%
{
;IF BLOCK FOUND, GO FIND ENTRY
if (BlockFound)
{
RegExMatch(A_LoopReadLine , "^(.*)=(.*)$", match) ;Find var name and text
if (match1)
{
EntriesList = % EntriesList match1 "|"
InputList = % InputList match2 "#"
StringSplit, EntryName, EntriesList, |, ;Separates all keys-list to separate EntryName(N) variables (pseudo-array)
StringSplit, Entry, InputList, #, ;Separates all text-list to separate Entry(N) variables (pseudo-array)
Category%CategoryTotal%Size++ ;Total size of a category
EntriesTotal++
GuiControl,, Loading, Please, wait until ini file loads. Loaded %EntriesTotal% entries... ;Read and show a raw key's text
}
Else ;IF STRING IS BLANK OR NEW CATEGORY
{
BlockFound := False
}
}
;IF BLOCK NOT FOUND, FIND BLOCK
if not (BlockFound)
{
RegExMatch(A_LoopReadLine , "^\[(.*)\]$", category)
if (category1)
{
BlockFound := True
CategoryTotal++ ;Categories counter
Category%CategoryTotal%Name = %category1% ;Category1Name = Name of the BLOCK #1
}
}
}
;====DEBUG SHOW LIST OF BLOCKS
; Message := 1
; While (Message <= CategoryTotal)
; {
; MessageText = % MessageText "Category #" Message " [" Category%Message%Name "] has " Category%Message%Size " Entries`n"
; Message++
; }
; MessageText = % MessageText "Total Entries: " EntriesTotal
; MsgBox, %MessageText%
;====DEBUG END
GuiControl,, Loading,
GuiControl, Enable, Save ;Enables Save button
GuiControl, Enable, OpenTrans ;Enables Open translation button
GuiControl,, EntriesListBox, %EntriesList% ;Put a Keys-list-text to the Keys-list-interface to pick
MsgBox, 4, Open, Done!`n`nPick a translating file?`n(Click No - if this is a first run)
IfMsgBox Yes
{
Goto, OpenTrans
}
Return
;====OPEN A TRANSLATION to merge current translate session with already translated keys
OpenTrans:
FileSelectFile, PickedFile, 3, %A_ScriptDir%,, Translation (*.ini)
if ErrorLevel
{
Return
}
Match1Index := 1 ;Key index, because not every key could has a translation
Loop, Read, %PickedFile%
{
RegExMatch(A_LoopReadLine , "^(.*)=(.*)$", match)
If (match1)
{
MatchIndex++
StringReplace, match2, match2, ``n, `n, All ;Replace AHK autoformatting to real `n (endl)
Translated%MatchIndex% = %match2% ;Add a translated text value to the current session
}
}
MsgBox, Done!
Return
;====SAVE TRANSLATION
Save:
Gui, Submit, NoHide ;Submit in advance to not lose the last translated key
Translated%TranslatingEntry% = %Translated% ;Save translated value
FileSelectFile, SavePath, S16, %A_ScriptDir%,, Language files (*.ini)
if ErrorLevel
{
Return
}
StringRight, ExtentionCheck, SavePath, 4 ;File extention check
if (ExtentionCheck != ".ini")
{
SavePath = %SavePath%.ini
}
;Writing process here
CategoryNow := 1
EntryCounter := 1 ;For (int i=1, i > Category.Size, i++)
Loop, %EntriesTotal%
{
if (EntryCounter > Category%CategoryNow%Size)
{
EntryCounter := 1
CategoryNow++
}
StringReplace, Translated%A_Index%, Translated%A_Index%, `n, ``n, All ;Replace endlines to 'n to store in a string
IniWrite, % Translated%A_Index%, %SavePath%, % Category%CategoryNow%Name, % EntryName%A_Index%
EntryCounter++
GuiControl,, Loading, Saving %A_Index% of %EntriesTotal% entries...
}
MsgBox, Done.
GuiControl,, Loading,
Return
;====ListBox key SELECTED
SelectEntry:
Gui, Submit, NoHide ;Save translation text
Translated%TranslatingEntry% = %Translated% ;Write translated text to its vatiable
StringReplace, Entry%EntriesListBox%, Entry%EntriesListBox%, ``n, `n, All ;Replace AHK autoformatting to real `n (endl)
GuiControl,, Translated, % Translated%EntriesListBox% ;Read and show a translation if stored
GuiControl,, Entry, % Entry%EntriesListBox% ;Read and show a raw key's text
TranslatingEntry = %EntriesListBox% ;Last ListBox index (needed to save when new key selected)
Return
GuiClose:
MsgBox, 4, Exit?, Exit?`nYOU MAY LOSE ALL UNSAVED DATA!
IfMsgBox No
{
Goto, Save
}
IfMsgBox Yes
{
ExitApp
}
Return