I have a huge project needing localization so I decided to write this snippet. It exports the application strings to the log screen.
The log screen will then display the application strings. Right click the log screen and select "Copy all to clipboard". Then paste into the "strings.xlsx" Excel file.
I hope it will be helpful.
You only need to add this code in your application :
and this sub to Localizator.bas :
The log screen will then display the application strings. Right click the log screen and select "Copy all to clipboard". Then paste into the "strings.xlsx" Excel file.
I hope it will be helpful.
You only need to add this code in your application :
B4X:
Sub B_ExportStrings_Click
Starter.loc.ExportStrings(Activity)
End Sub
and this sub to Localizator.bas :
B4X:
'Tested with B4A only
#if B4A
'Exports strings from Labels and EditTexts to the log.
' Then you may copy it into the Excel file to initialize translations.
' Tested successfuly with TabStrip
Public Sub ExportStrings(PanelOrActivity As Panel)
Log("'=== Localizator exported strings =================================================")
Log("key" & Chr(9) & "en")
For Each v As View In PanelOrActivity.GetAllViewsRecursive
If v Is Label Then 'this will catch all of Label subclasses which includes EditText, Button and others
Dim lbl As Label = v
ExportView(lbl.Text)
Else If v Is EditText Then
Dim et As EditText = v
ExportView(et.Hint)
' Else If v Is Activity Then
' Log("' Activity ---------------------")
' Else If v Is Panel Then
' Log("' Panel ------------------------")
End If
Next
Log("'=================================================================================")
End Sub
Private Sub ExportView(View_text As String)
If View_text.Length > 1 Then ' To avoid icons to be exported
If View_text.Trim <> "" Then Log(View_text & Chr(9) & View_text)
End If
End Sub
#end If
Last edited: