Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New translations #592

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions ClimsoftVer4/ClimsoftVer4/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
</startup>
<applicationSettings>
<ClimsoftVer4.My.MySettings>
<setting name="defaultDatabase" serializeAs="String">
<value>server=localhost;database=mariadb_climsoft_db_v4;port=3308;</value>
</setting>
<setting name="defaultRLocation" serializeAs="String">
<value>C:\Program Files\R\R-3.2.1</value>
</setting>
<setting name="defaultDatabase" serializeAs="String">
<value>server=localhost;database=mariadb_climsoft_db_v4;port=3308;</value>
</setting>
<setting name="defaultRLocation" serializeAs="String">
<value>C:\Program Files\R\R-3.2.1</value>
</setting>
<setting name="localDatabase" serializeAs="String">
<value>Climsoft4.ldb</value>
</setting>
</ClimsoftVer4.My.MySettings>
</applicationSettings>
<entityFramework>
Expand All @@ -46,12 +49,15 @@
</connectionStrings>
<userSettings>
<ClimsoftVer4.My.MySettings>
<setting name="rememberUsername" serializeAs="String">
<value>False</value>
</setting>
<setting name="rememberedUsername" serializeAs="String">
<value />
</setting>
<setting name="rememberUsername" serializeAs="String">
<value>False</value>
</setting>
<setting name="rememberedUsername" serializeAs="String">
<value />
</setting>
<setting name="currentLanguageCode" serializeAs="String">
<value>en</value>
</setting>
</ClimsoftVer4.My.MySettings>
</userSettings>
</configuration>
Binary file added ClimsoftVer4/ClimsoftVer4/Climsoft4.ldb
Binary file not shown.
16 changes: 16 additions & 0 deletions ClimsoftVer4/ClimsoftVer4/ClimsoftVer4.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
<MyType>WindowsForms</MyType>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -58,6 +60,9 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Data" />
<Reference Include="System.Data.SQLite, Version=1.0.111.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<HintPath>..\packages\System.Data.SQLite.Core.1.0.111.0\lib\net451\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Numerics" />
Expand Down Expand Up @@ -91,6 +96,7 @@
<Compile Include="clsClimsoftSettings.vb" />
<Compile Include="clsLanguageTranslation.vb" />
<Compile Include="clsProducts.vb" />
<Compile Include="clsSimpleTranslateTool.vb" />
<Compile Include="clsTableFilter.vb" />
<Compile Include="dataEntryGlobalRoutines.vb" />
<Compile Include="formAgro1.Designer.vb">
Expand Down Expand Up @@ -1141,6 +1147,9 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<None Include="Climsoft4.ldb">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="My Project\Application.myapp">
<Generator>MyApplicationCodeGenerator</Generator>
<LastGenOutput>Application1.Designer.vb</LastGenOutput>
Expand Down Expand Up @@ -1171,6 +1180,13 @@
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
<Import Project="..\packages\System.Data.SQLite.Core.1.0.111.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.111.0\build\net451\System.Data.SQLite.Core.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\System.Data.SQLite.Core.1.0.111.0\build\net451\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\System.Data.SQLite.Core.1.0.111.0\build\net451\System.Data.SQLite.Core.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
4 changes: 4 additions & 0 deletions ClimsoftVer4/ClimsoftVer4/FrmConversionDewPointRh.vb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ errhandler:
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
Me.Close()
End Sub

Private Sub FrmConversionDewPointRh_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SimpleTranslateTool.translateForm(Me)
End Sub
End Class
21 changes: 21 additions & 0 deletions ClimsoftVer4/ClimsoftVer4/My Project/Settings.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions ClimsoftVer4/ClimsoftVer4/My Project/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@
<Setting Name="rememberedUsername" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="localDatabase" Type="System.String" Scope="Application">
<Value Profile="(Default)">Climsoft4.ldb</Value>
</Setting>
<Setting Name="currentLanguageCode" Type="System.String" Scope="User">
<Value Profile="(Default)">en</Value>
</Setting>
</Settings>
</SettingsFile>
188 changes: 188 additions & 0 deletions ClimsoftVer4/ClimsoftVer4/clsSimpleTranslateTool.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
' CLIMSOFT - Climate Database Management System
' Copyright (C) 2019
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
Imports System.Data.SQLite

Public Class SimpleTranslateTool
Public Shared Function listLanguages() As AvailableLanguages
Dim builder As New SQLiteConnectionStringBuilder()
Dim command As SQLiteCommand
Dim connection As New SQLiteConnection()
Dim currentIndex As Integer = 0
Dim datareader As SQLiteDataReader
Dim dict As New Dictionary(Of String, String)
Dim languages As New List(Of String)
Dim languageCodes As New List(Of String)
Dim selectedIndex As Integer = 0

Try
builder.FailIfMissing = True
builder.DataSource = My.Settings.localDatabase
connection = New SQLiteConnection(builder.ConnectionString)
connection.Open()
command = connection.CreateCommand()
command.CommandText = "SELECT code, language FROM available_languages"
datareader = command.ExecuteReader()
While (datareader.Read())
languageCodes.Add(datareader.GetValue(0))
languages.Add(datareader.GetString(1))
If datareader.GetValue(0) = "en" Then
selectedIndex = currentIndex
End If
currentIndex += 1
End While
Catch ex As Exception
' If processing information from SQLite fails for any reason then return
' English as the only option (if a connection is open then close it).
connection.Close()
languageCodes.Add("en")
languages.Add("English")
selectedIndex = 0
End Try

'For Each keyValue As String() In languages.Zip(Of String, String())(languageCodes, Tuple.Create())
For Each keyValue In languages.Zip(Of String, Object)(languageCodes, Function(s1, s2) Tuple.Create(s1, s2))
dict.Add(keyValue.Item1, keyValue.Item2)
Next

Return New AvailableLanguages With {
.languageCodes = languageCodes,
.languages = languages,
.selectedIndex = selectedIndex,
.lookupCode = dict
}
End Function


Public Shared Function translateOpenForms(Optional language As String = "")
Dim languageCode As String
For Each frm As Form In My.Application.OpenForms
languageCode = translateForm(frm, language)
Next
Return languageCode
End Function

Public Shared Function translateForm(frm As Form, Optional language As String = "")
' Change text in all open forms to new language choice
Dim builder As New SQLiteConnectionStringBuilder()
Dim command As SQLiteCommand
Dim connection As New SQLiteConnection()
Dim controlName As String
Dim datareader As SQLiteDataReader
Dim flag As String
Dim formName As String
Dim lang As String
Dim languageCode As String
Dim keyParts As String()
Dim parent As String
Dim parents As String()
Dim parentParts As String()
Dim parentType As String
Dim propertyName As String
Dim startswith As String
Dim value As String

If String.IsNullOrEmpty(language) Then
languageCode = My.Settings.currentLanguageCode
Else
languageCode = listLanguages().lookupCode(language)
End If

'Try
builder.FailIfMissing = True
builder.DataSource = My.Settings.localDatabase
connection = New SQLiteConnection(builder.ConnectionString)
connection.Open()
command = connection.CreateCommand()

' For the current languageCode and form.Name get all translation entries
startswith = String.Format("{0}\_\_{1}\_\_", languageCode, frm.Name)
command.CommandText = String.Format(
"SELECT name, value, parent, flag from translations WHERE name LIKE '{0}%' ESCAPE '\';", startswith)
datareader = command.ExecuteReader()

'MsgBox("SELECT name, value, parent, flag from translations WHERE name LIKE '{0}%' ESCAPE '\';", startswith)

While (datareader.Read())
' Currenty the strings we are splitting contain two consecutive understored "__"
' Splitting on `__` is the same as spliting on `_` and will return empty strings between each pair of underscores
keyParts = datareader.GetValue(0).Split("_")
lang = keyParts(0)
formName = keyParts(2)
controlName = keyParts(4)
propertyName = keyParts(6)
value = datareader.GetString(1)
parents = datareader.GetString(2).Split(".")
' It's always safe to request details of the first parent (root parent)
parentParts = parents(0).Split(":")
parent = parentParts(0)
flag = datareader.GetString(3)

Try
If Not String.IsNullOrEmpty(parent) Then

' First parent's indicator of type
parentType = parentParts(1)

' Is there a second parent?
If parents.Length > 1 Then
' When there is a second parent, this usually indicates a submenu item
' E.g. MenuStrip2:M.mnuInput:S
Dim secondParentParts = parents(1).Split(":")
Dim secondParent = secondParentParts(0)
Dim secondParentType = secondParentParts(1)
Dim menu As MenuStrip
Dim toolmenu As ToolStripMenuItem
menu = frm.Controls(parent)
toolmenu = menu.Items().Item(secondParent)
CallByName(toolmenu.DropDownItems().Item(controlName), propertyName, CallType.Set, value)

ElseIf parentType = "C" Then
' This will work for standard controls that are inside a panel
CallByName(frm.Controls(parent).Controls(controlName), propertyName, CallType.Set, value)
ElseIf parentType = "M" Then
' This will work for the primary menu items on a menu strip (but not submenu items)
Dim menu As MenuStrip
menu = frm.Controls(parent)
CallByName(menu.Items().Item(controlName), propertyName, CallType.Set, value)
End If

ElseIf controlName = "Me" Then
CallByName(frm, propertyName, CallType.Set, value)
Else
CallByName(frm.Controls(controlName), propertyName, CallType.Set, value)
End If

Catch ex As Exception
' MsgBox(">> " & parent & " " & frm.Name & " " & controlName & " " & propertyName & " " & value & "::" & ex.Message)
End Try

End While
'Catch ex As Exception
' Throw
'Finally
connection.Close()
'End Try

Return languageCode
End Function
End Class

Public Class AvailableLanguages
Public Property languageCodes As List(Of String)
Public Property languages As List(Of String)
Public Property selectedIndex As Integer
Public Property lookupCode As Dictionary(Of String, String)
End Class
2 changes: 2 additions & 0 deletions ClimsoftVer4/ClimsoftVer4/formAWSRealTime.vb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Public Class formAWSRealTime
End Sub

Private Sub formAWSRealTime_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SimpleTranslateTool.translateForm(Me)

pnlProcessing.Dock = DockStyle.Right
pnlProcessing.Visible = True
' database Connect
Expand Down
2 changes: 2 additions & 0 deletions ClimsoftVer4/ClimsoftVer4/formMetadata.vb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Public Class formMetadata
End Sub

Private Sub formMetadata_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SimpleTranslateTool.translateForm(Me)

dbConnectionString = frmLogin.txtusrpwd.Text
dbconn.ConnectionString = dbConnectionString
dbconn.Open()
Expand Down
1 change: 1 addition & 0 deletions ClimsoftVer4/ClimsoftVer4/formPaperArchive.vb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@
End Sub

Private Sub formPaperArchive_Load(sender As Object, e As EventArgs) Handles Me.Load
SimpleTranslateTool.translateForm(Me)

dbConnectionString = frmLogin.txtusrpwd.Text
dbconn.ConnectionString = dbConnectionString
Expand Down
1 change: 1 addition & 0 deletions ClimsoftVer4/ClimsoftVer4/formProducts.vb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Public Class frmProducts
Dim kounts As Integer
Dim SelectedProduct
Private Sub formProductsSelect_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SimpleTranslateTool.translateForm(Me)

'MyConnectionString = "server=127.0.0.1; uid=root; pwd=admin; database=mysql_climsoft_db_v4"
MyConnectionString = frmLogin.txtusrpwd.Text
Expand Down
2 changes: 1 addition & 1 deletion ClimsoftVer4/ClimsoftVer4/frmAction.vb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Public Class frmAction
End Sub

Private Sub frmAction_Load(sender As Object, e As EventArgs) Handles MyBase.Load
autoTranslate(Me)

End Sub

Private Sub cmdHelp_Click(sender As Object, e As EventArgs) Handles cmdHelp.Click
Expand Down
2 changes: 2 additions & 0 deletions ClimsoftVer4/ClimsoftVer4/frmChangeOwnPassword.vb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
End Sub

Private Sub frmChangeOwnPassword_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SimpleTranslateTool.translateForm(Me)

msgNotYetImplemented = "Not yet implemented!"
msgWrongPasswordConfirmation = "Wrong confirmation of password!"
msgPasswordTooShort = "Password length must be >=6 characters!"
Expand Down
2 changes: 2 additions & 0 deletions ClimsoftVer4/ClimsoftVer4/frmChangePassword.vb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
End Sub

Private Sub frmChangePassword_Load(sender As Object, e As EventArgs) Handles MyBase.Load
SimpleTranslateTool.translateForm(Me)

msgNotYetImplemented = "Not yet implemented!"
msgWrongPasswordConfirmation = "Wrong confirmation of password!"
msgPasswordTooShort = "Password length must be >=6 characters!"
Expand Down
Loading