Created
February 10, 2015 13:39
-
-
Save kamera25/3b292a08b14a629e9a73 to your computer and use it in GitHub Desktop.
ogd(Libreoffice Draw)データから、POファイルを生成する(書きかけ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM ***** BASIC ***** | |
Sub TranslateMessage | |
Dim iNumber As Integer | |
Dim aFile As String | |
Dim sText As String | |
' sText = InputBox ("poファイルのフルパスを入力してください。 ","poファイルのパス") | |
'パスの入力 | |
' iNumber = Freefile | |
' Open sText For Input As #iNumber | |
' MsgBox ( sText + "を開きます。", 64, "POファイルの読み込み") | |
' Replace( "", "Raspberry", "ラズベリー") | |
ReplaceFromTemplate | |
End Sub | |
Function ReplaceFromTemplate | |
Dim objDoc As Object | |
Dim Page As Object | |
Dim Section As Object | |
Dim maxPage As Integer | |
objDoc = StarDesktop.CurrentComponent | |
Page = objDoc.drawPages(3) | |
Section = Page.getByIndex(3) | |
maxPage = objDoc.getDrawPages().getcount() | |
' ループでセクションを回す | |
Dim i As Integer | |
i = 0 | |
Do While i < Page.getCount() | |
Section = Page.getByIndex(i) | |
Section.setString( Replace( Section.String, "themselves", "自分自身")) | |
i = i + 1 | |
Loop | |
'Page = objDoc.drawPages(0) | |
'Section.setString( Replace( Section.String, "Human", "人間")) | |
Msgbox("ファイル名 : " & maxPage) | |
End Function | |
Function MakePoFile | |
Dim sPath As String | |
Dim File As String | |
Dim iNumber As Integer | |
Dim maxPage As Integer | |
maxPage = StarDesktop.CurrentComponent.getDrawPages().getcount() | |
'パスの入力 | |
'sPath = InputBox ("poファイルを保存する、パスを入力してください。 ","poファイルの保存パス") | |
sPath = "/home/taka/test.po" | |
iNumber = Freefile | |
Open sPath For Output As #iNumber | |
'POファイルの作成 | |
MakeHeader( iNumber) | |
Dim i As Integer | |
i = 0 | |
Do While i < maxPage | |
WritePOFileFromPage( i, iNumber) | |
i = i + 1 | |
Loop | |
Close #iNumber | |
'Save complete!! | |
Msgbox( sPath + " へPOファイルの出力が終了しました。") | |
End Function | |
Function WritePOFileFromPage ( pageNum As Integer, iNumber As Integer) | |
Dim objDoc As Object | |
Dim Page As Object | |
Dim Section As Object | |
Dim FileName As String | |
FileName = "Raspberry_Pi_Education_Manual_translation.odg" | |
objDoc = StarDesktop.CurrentComponent | |
Page = objDoc.drawPages(pageNum) | |
Dim i As Integer | |
i = 0 | |
Do While i < Page.getCount() | |
Section = Page.getByIndex(i) | |
If Section.String <> "" And Section.String <> " " Then | |
Dim msgid As String | |
'改行を取り除く処理 | |
msgid = Replace( Section.String, "\", "\\") | |
msgid = Replace( msgid, Chr$(13), "\n") | |
msgid = Replace( msgid, Chr$(10), "\n") | |
Print #iNumber, "#: " + FileName + ":" + pageNum | |
Print #iNumber, "msgid """ + msgid + """" | |
Print #iNumber, "msgstr """"" | |
Print #iNumber, "" | |
End If | |
i = i + 1 | |
Loop | |
End Function | |
Function MakeHeader( #iNumber As Integer) | |
Dim projectIdVer As String | |
Dim lastTranslator As String | |
Dim lastTranslatorMail As String | |
Dim languageTeam As String | |
Dim langIndentifier As String | |
projectIdVer = "raspberry_pi_education_manual_translation master" | |
'入力ボックス部 | |
lastTranslator = InputBox ("あなたの名前を入力してください(英語)。 ","名前の入力") | |
lastTranslatorMail = InputBox ("あなたのメールアドレスを入力してください。 ","メールアドレス入力") | |
languageTeam = InputBox ("言語チーム名を入力してください(英語)。(例:日本なら「Japanese」) ","言語チーム名の入力") | |
langIndentifier = InputBox ("言語チームの識別子を入れてください。(例:日本なら「ja」) ","言語チームの識別子") | |
Print #iNumber, "msgid """"" | |
Print #iNumber, "msgstr """"" | |
Print #iNumber, """Project-Id-Version: " + projectIdVer + "\n""" | |
'Print #iNumber, """POT-Creation-Date: " + +"\n""" | |
'Print #iNumber, """PO-Revision-Date: " + + "\n""" | |
Print #iNumber, """Last-Translator: " + lastTranslator + "<" + lastTranslatorMail + ">\n""" | |
Print #iNumber, """Language-Team: " + langageTeam + "<" + lastTranslatorMail + ">\n""" | |
Print #iNumber, """Language: " + langIndentifier + "\n""" | |
Print #iNumber, """MIME-Version: 1.0\n""" | |
Print #iNumber, """Content-Type: text/plain; charset=UTF-8\n""" | |
Print #iNumber, """Content-Transfer-Encoding: 8bit\n""" | |
Print #iNumber, "" | |
End Function | |
Function Replace(Source As String, Search As String, NewPart As String) | |
Dim Result As String | |
Dim StartPos As Long | |
Dim CurrentPos As Long | |
Result = "" | |
StartPos = 1 | |
CurrentPos = 1 | |
If Search = "" Then | |
Result = Source | |
Else | |
Do While CurrentPos <> 0 | |
CurrentPos = InStr(StartPos, Source, Search) | |
If CurrentPos <> 0 Then | |
Result = Result + Mid(Source, StartPos, _ | |
CurrentPos - StartPos) | |
Result = Result + NewPart | |
StartPos = CurrentPos + Len(Search) | |
Else | |
Result = Result + Mid(Source, StartPos, Len(Source)) | |
End If ' Position <> 0 | |
Loop | |
End If | |
Replace = Result | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment