none
Application that does really simple translations RRS feed

  • Question

  • Hello,

    I am tempted to create a simple application that does simple translation tasks. And by simple I mean really simple!

    Situation: I work at a manufacturing company and 90% of our technical drawings are made in English, always the same words in the same context. In the rare occasion the client requests documents in another language, mainly German or French.

    I would like to create a application that does this kind of simple translation for the drafting engineer. But I am not sure how to store the translations. So I need some advice.

    My Idea:

    - Create a txt file that contains each possible word on a new line, and add comma seperated translations in the same line, always in the same order.

    Example line

    • English,Englisch,Anglais
    • Pipe,Rohr,Pipe

    Or are there better solutions to store the translation and have them easy to edit?

    Tuesday, May 8, 2018 7:10 AM

Answers

  • Hello,

    The following is fairly simple. In the MainForm I have a DataGridView showing available translations. To add, edit or remove the EditorForm permits this.

    Class to read and write to xml file

    Imports System.IO
    Public Class Operations
    
        Private fileName As String = Path.Combine(
            AppDomain.CurrentDomain.BaseDirectory, "Translations.xml")
    
        Public Function Read() As DataTable
            Dim ds = CreateDataSet()
    
            If IO.File.Exists(fileName) Then
                ds.ReadXml(fileName)
                If ds.Tables.Count = 0 Then
                    ds.Tables.Add(CreateTable())
                End If
            Else
                ds.Tables.Add(CreateTable())
            End If
    
            Return ds.Tables("Translations")
    
        End Function
        Public Sub Write(pDataTable As DataTable)
            pDataTable.AcceptChanges()
            Dim ds = CreateDataSet()
            Dim dt As DataTable = pDataTable.Copy()
            ds.Tables.Add(dt)
            ds.WriteXml(fileName)
        End Sub
        Private Function CreateDataSet() As DataSet
            Return New DataSet With {.DataSetName = "TechnicalDrawingData"}
        End Function
        Private Function CreateTable() As DataTable
            Dim ds As DataSet = CreateDataSet()
            Dim dt As New DataTable With {.TableName = "Translations"}
            dt.Columns.Add(New DataColumn() With {.ColumnName = "English", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn() With {.ColumnName = "German", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn() With {.ColumnName = "French", .DataType = GetType(String)})
    
            ds.Tables.Add(dt)
    
            Return dt.Copy()
    
        End Function
    End Class
    

    MainForm has one button.

    Public Class MainForm
        Private _bs As New BindingSource
        Private Sub MainForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            Dim ops = New Operations
            _bs.DataSource = ops.Read
            DataGridView1.DataSource = _bs
        End Sub
    
        Private Sub cmdEditor_Click(sender As Object, e As EventArgs) Handles cmdEditor.Click
            Dim f As New EditorForm(CType(_bs.DataSource, DataTable))
            Try
                f.ShowDialog()
            Finally
                f.Dispose()
            End Try
        End Sub
    End Class

    EditorForm (saves back to xml on closing which you may want to alter or ask the user if they are sure to save or not)

    Public Class EditorForm
        Public Property DataTransTable() As DataTable
        Public Sub New()
            InitializeComponent()
        End Sub
        Public Sub New(pDataTable As DataTable)
            InitializeComponent()
            DataTransTable = pDataTable
        End Sub
        Private Sub EditorForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            DataGridView1.DataSource = DataTransTable
        End Sub
        Private Sub EditorForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            Dim ops As New Operations
            ops.Write(DataTransTable)
        End Sub
        Private Sub cmdCommit_Click(sender As Object, e As EventArgs) Handles cmdCommit.Click
            DataTransTable.AcceptChanges()
        End Sub
    End Class
    

    In your app you can show the data in any control you care too. Lastly, you could use a TextFieldParer to get at your data and write back using a StringBuilder and append to a string then save back to a file.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, May 8, 2018 10:28 AM
    Moderator

All replies

  • You know that applications which are really simple to use are the most difficult ones there are to make. 

    Your solution sounds very difficult to use because it needs probably a big instruction manual. 

    First invent how the user wants it, before you rule them to use your way of what is simple to avoid disappointments.


    And for translations, don't start until you have a full team of experts who know very well the involved languages. 

    Your sample could be more obvious:

    Pipe, Tabakspfeife, pipe (from every-bodies first French lesson, "Papa fumes la pipe"


    Success
    Cor





    Tuesday, May 8, 2018 9:01 AM
  • Hello,

    The following is fairly simple. In the MainForm I have a DataGridView showing available translations. To add, edit or remove the EditorForm permits this.

    Class to read and write to xml file

    Imports System.IO
    Public Class Operations
    
        Private fileName As String = Path.Combine(
            AppDomain.CurrentDomain.BaseDirectory, "Translations.xml")
    
        Public Function Read() As DataTable
            Dim ds = CreateDataSet()
    
            If IO.File.Exists(fileName) Then
                ds.ReadXml(fileName)
                If ds.Tables.Count = 0 Then
                    ds.Tables.Add(CreateTable())
                End If
            Else
                ds.Tables.Add(CreateTable())
            End If
    
            Return ds.Tables("Translations")
    
        End Function
        Public Sub Write(pDataTable As DataTable)
            pDataTable.AcceptChanges()
            Dim ds = CreateDataSet()
            Dim dt As DataTable = pDataTable.Copy()
            ds.Tables.Add(dt)
            ds.WriteXml(fileName)
        End Sub
        Private Function CreateDataSet() As DataSet
            Return New DataSet With {.DataSetName = "TechnicalDrawingData"}
        End Function
        Private Function CreateTable() As DataTable
            Dim ds As DataSet = CreateDataSet()
            Dim dt As New DataTable With {.TableName = "Translations"}
            dt.Columns.Add(New DataColumn() With {.ColumnName = "English", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn() With {.ColumnName = "German", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn() With {.ColumnName = "French", .DataType = GetType(String)})
    
            ds.Tables.Add(dt)
    
            Return dt.Copy()
    
        End Function
    End Class
    

    MainForm has one button.

    Public Class MainForm
        Private _bs As New BindingSource
        Private Sub MainForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            Dim ops = New Operations
            _bs.DataSource = ops.Read
            DataGridView1.DataSource = _bs
        End Sub
    
        Private Sub cmdEditor_Click(sender As Object, e As EventArgs) Handles cmdEditor.Click
            Dim f As New EditorForm(CType(_bs.DataSource, DataTable))
            Try
                f.ShowDialog()
            Finally
                f.Dispose()
            End Try
        End Sub
    End Class

    EditorForm (saves back to xml on closing which you may want to alter or ask the user if they are sure to save or not)

    Public Class EditorForm
        Public Property DataTransTable() As DataTable
        Public Sub New()
            InitializeComponent()
        End Sub
        Public Sub New(pDataTable As DataTable)
            InitializeComponent()
            DataTransTable = pDataTable
        End Sub
        Private Sub EditorForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            DataGridView1.DataSource = DataTransTable
        End Sub
        Private Sub EditorForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            Dim ops As New Operations
            ops.Write(DataTransTable)
        End Sub
        Private Sub cmdCommit_Click(sender As Object, e As EventArgs) Handles cmdCommit.Click
            DataTransTable.AcceptChanges()
        End Sub
    End Class
    

    In your app you can show the data in any control you care too. Lastly, you could use a TextFieldParer to get at your data and write back using a StringBuilder and append to a string then save back to a file.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, May 8, 2018 10:28 AM
    Moderator
  • Not sure what is going on here... my posts keep coming up blank...
    Tuesday, May 8, 2018 12:24 PM
    Moderator
  • I agree with Karen that XML is probably the easiest way to go.  I would likely just construct the XML file in a text editor (VS has good XML editing support).
    First I would define a simple XML file to hold the translation data:

    <?xml version="1.0" encoding="utf-8" ?>
    <translations>
      <word value="pipe">
        <translation lang="german" value="???" />
        <translation lang="french" value="???" />
        <translation lang="spanish" value="???" />
      </word>
    </translations>

    I would probably use an Enum to define the languages supported, although this is not strictly necessary and could be replaced with a string instead:

    Public Enum SupportedLanguage
        French
        German
        Spanish
    End Enum

    Next I would have a dictionary to hold the parsed XML data and a method to load the dictionary (likely called on Form.Load):

    Private Translations As New Dictionary(Of String, Dictionary(Of SupportedLanguage, String))
    
    Private Sub LoadTranslations()
        Dim xlationDoc = XDocument.Load("translations.xml")
        For Each element In xlationDoc.Root.<word>
            Translations.Add(element.@value, New Dictionary(Of SupportedLanguage, String))
            For Each xlation In element.<translation>
                Translations(element.@value).Add([Enum].Parse(GetType(SupportedLanguage), xlation.@lang, True), xlation.@value)
            Next
        Next
    End Sub

    Finally there would be a method to perform a translation:

    Private Function Translate(word As String, language As SupportedLanguage) As String
        If Translations.ContainsKey(word) Then
            If Translations(word).ContainsKey(language) Then
                Return Translations(word)(language)
            End If
        End If
        Return $"Missing Translation for {word} in {language}"
    End Function

    Now you can call the Translate() method passing a word and target language whenever a translation is needed.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Tuesday, May 8, 2018 12:28 PM
    Moderator
  • For some reason the post would fail with the XML code block.  Please forgive the lack of formatting on the XML file example.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, May 8, 2018 12:29 PM
    Moderator
  • Karen and Reed,

    Why are you both so often replying with showing in real life not working beginners code, instead handling the real problems? 

    Even in the English language there are endless synonyms for the same word. Therefore try your solutions only for the synonyms of English words. Let us take a simple one  to start with "drunk". 

    Do you really think most contributors including me could not give your kind of reply?


    Success 
    Cor


    Success
    Cor


    Tuesday, May 8, 2018 12:59 PM
  • Karen and Reed,

    Why are you both so often replying with showing in real life not working beginners code, instead handling the real problems? 

    Even in the English language there are endless synonyms for the same word. Therefore try your solutions only for the synonyms of English words. Let us take a simple one  to start with "drunk". 

    Do you really think most contributors including me could not give your kind of reply?


    Success 
    Cor


    Success
    Cor


    I have no idea what you are going on about, but it doesn't seem relevant to the thread.  The OP asked for suggestions on how to handle "very simple" translations, using 1-1 mappings of a known set of words into a known set of languages.  The solutions offered by Karen and I address this requirement with simple code solutions.

    One of the usage guidelines for the forum is to avoid challenging other contributors simply because you don't like their response.  So long as the response is on-topic and contains working, relevant information, it should be left to the OP to decide what is useful.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Tuesday, May 8, 2018 1:14 PM
    Moderator
  • Hello,

    The following is fairly simple. In the MainForm I have a DataGridView showing available translations. To add, edit or remove the EditorForm permits this.

    Class to read and write to xml file

    Imports System.IO
    Public Class Operations
    
        Private fileName As String = Path.Combine(
            AppDomain.CurrentDomain.BaseDirectory, "Translations.xml")
    
        Public Function Read() As DataTable
            Dim ds = CreateDataSet()
    
            If IO.File.Exists(fileName) Then
                ds.ReadXml(fileName)
                If ds.Tables.Count = 0 Then
                    ds.Tables.Add(CreateTable())
                End If
            Else
                ds.Tables.Add(CreateTable())
            End If
    
            Return ds.Tables("Translations")
    
        End Function
        Public Sub Write(pDataTable As DataTable)
            pDataTable.AcceptChanges()
            Dim ds = CreateDataSet()
            Dim dt As DataTable = pDataTable.Copy()
            ds.Tables.Add(dt)
            ds.WriteXml(fileName)
        End Sub
        Private Function CreateDataSet() As DataSet
            Return New DataSet With {.DataSetName = "TechnicalDrawingData"}
        End Function
        Private Function CreateTable() As DataTable
            Dim ds As DataSet = CreateDataSet()
            Dim dt As New DataTable With {.TableName = "Translations"}
            dt.Columns.Add(New DataColumn() With {.ColumnName = "English", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn() With {.ColumnName = "German", .DataType = GetType(String)})
            dt.Columns.Add(New DataColumn() With {.ColumnName = "French", .DataType = GetType(String)})
    
            ds.Tables.Add(dt)
    
            Return dt.Copy()
    
        End Function
    End Class

    MainForm has one button.

    Public Class MainForm
        Private _bs As New BindingSource
        Private Sub MainForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            Dim ops = New Operations
            _bs.DataSource = ops.Read
            DataGridView1.DataSource = _bs
        End Sub
    
        Private Sub cmdEditor_Click(sender As Object, e As EventArgs) Handles cmdEditor.Click
            Dim f As New EditorForm(CType(_bs.DataSource, DataTable))
            Try
                f.ShowDialog()
            Finally
                f.Dispose()
            End Try
        End Sub
    End Class

    EditorForm (saves back to xml on closing which you may want to alter or ask the user if they are sure to save or not)

    Public Class EditorForm
        Public Property DataTransTable() As DataTable
        Public Sub New()
            InitializeComponent()
        End Sub
        Public Sub New(pDataTable As DataTable)
            InitializeComponent()
            DataTransTable = pDataTable
        End Sub
        Private Sub EditorForm_Shown(sender As Object, e As EventArgs) Handles Me.Shown
            DataGridView1.DataSource = DataTransTable
        End Sub
        Private Sub EditorForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
            Dim ops As New Operations
            ops.Write(DataTransTable)
        End Sub
        Private Sub cmdCommit_Click(sender As Object, e As EventArgs) Handles cmdCommit.Click
            DataTransTable.AcceptChanges()
        End Sub
    End Class

    In your app you can show the data in any control you care too. Lastly, you could use a TextFieldParer to get at your data and write back using a StringBuilder and append to a string then save back to a file.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thank you karen, way better than my poor idea! You are the best!
    Tuesday, May 8, 2018 1:23 PM
  • Hi MechanicalEngineer, Can you come back if your first users did stratified use it a week? And then tell their reactions?

    Karen, points again, however, the forum is once again gone down in the usability of the quality of the answer. 

     

    Maybe what do you think what the problem is. That is that you cannot give any good solutions anymore because somebody drops down some beginners code which give the idea to be a solution. But makes persons to stop when they come to the conclussion it does not work. 

    Which experienced developers know already because they tried the same. 


    Success
    Cor



    Tuesday, May 8, 2018 1:32 PM
  • Hi Cor,

    I don't know why you are so negative? I asked a question and the forum supplied a answer. You are right, there are alot of synonyms for words, but in my specific case this is NOT relevant.

    Words like DRUNK would never show in my translations.. why? we don't sell drunk.. We sell metal plates, pipes, flanges. These words are easy to translate because the context is known to me. I am NOT trying to translate a book or even a simple sentence.

    For example translating a Bill of Materials is the first goal (list of items that are included in the product).

    • 1x Pipe Ø100 x 5 - lg. 1000mm
    • 2x Plate 450 x 450 x 10mm
    • 1x Flange DN500 PN10 - acc. ASME B16.5

    Translation would return in German

    • 1x Rohr Ø100 x 5 - lg. 1000mm
    • 2x Blech 450 x 450 x 10mm
    • 1x Flansch DN500 PN10 - nach. ASME B16.5

    The supplied answer can handle this just fine. I was just asking what was the best way to store there word translations. And please note that for me the sample above covers 70% of the performed translations...

    Additionally, I already implemented the code and first reactions were good.. Just need to work some more on the side-by-side translation UI, so the user can see all translations that were made and accept or decline them.



    Wednesday, May 9, 2018 11:18 AM
  • Hi Cor,

    I don't know why you are so negative? I asked a question and the forum supplied a answer. You are right, there are alot of synonyms for words, but in my specific case this is NOT relevant.



    You call it negative, I call it disappointed. 

    if you had given this reaction direct as reply on my first reply, others could have given you more solutions. I don't say better, but at least those who includes for instance alternatives, which is not difficult to do. 

    A pity that you saw it as negative. Yesterday I saw an old documentary about Henry Ford, he had in a way also that kind of behaviour you show in this thread. What could it have been if he had not.

    https://en.wikipedia.org/wiki/Henry_Ford


    Success
    Cor

    Wednesday, May 9, 2018 11:34 AM
  • I saw your and Karen's reply at the same time, marked Karen's reply as answer and thanked her. What was wrong with that behavior?

    Also I am flattered that you somewhat compare me with mister Ford he was a brilliant mind who made a firm stamp on the world as we know it today.

    But I will keep it in mind, and I will answer all comments in the question from now on.

    Thanks for the contribution.

    Wednesday, May 9, 2018 11:46 AM
  • I saw your and Karen's reply at the same time, marked Karen's reply as answer and thanked her. What was wrong with that behavior?

    Also I am flattered that you somewhat compare me with mister Ford he was a brilliant mind who made a firm stamp on the world as we know it today.

    But I will keep it in mind, and I will answer all comments in the question from now on.

    Thanks for the contribution.

    I wrote especially Henry Ford, not Edsel. Henry was the guy who created a firm with the slogan. "We sell T-Fords available in every color as long as it is black". 

    :-)

    Be aware, here you take again the same conclusion as in this thread. 

    :-)


    Success
    Cor


    Wednesday, May 9, 2018 11:52 AM
  • I think, the firm slogan wasn't "We sell T-Fords available in every color as long as it is black" but that quote was about the Ford Model T specific.

    As for the conclusion part, maybe I don't get it because English is not my native tongue.. please elaborate in Dutch? I assume you are from The Netherlands?

    Wednesday, May 9, 2018 12:23 PM
  • I saw your and Karen's reply at the same time, marked Karen's reply as answer and thanked her. What was wrong with that behavior?

    Also I am flattered that you somewhat compare me with mister Ford he was a brilliant mind who made a firm stamp on the world as we know it today.

    But I will keep it in mind, and I will answer all comments in the question from now on.

    Thanks for the contribution.

    @MechanicalEngineer:

    Please don't let these kinds of replies change your behavior.  What you did was fine.  Those of us who fluently understand English (and/or have worked in a similar situation to yours for nearly two decades... eh-hem), understood your requirement perfectly.  The thread is now becoming bloated with all of this off-topic debate that has nothing to do with the question.  Your requirement was clear and the answers provided by Karen and myself were on-topic and relevant.  There is no need to respond to things that clearly have nothing to do with the requirement.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Wednesday, May 9, 2018 12:25 PM
    Moderator