locked
Translating Messages in Visual Basic RRS feed

  • Question

  • Hello,

    I was working on my own language and decided to create a translator. I want that for example the letter "A" in Textbox One is "Ba" in Textbox Two. And if I create entire sentences they make sense in both languages. It would be great if you could help me. Thank you!

    Friday, June 29, 2018 12:41 AM

Answers

  • Hi

    From your description, I think you could try with a Dictionary(Of String, String).

    With such a Dictionary, an entry in TextBox1 as the Index into the Dictionary would return the Translation.

    here is some very very basic code to show the bare bones of what I mean above. There is no provisions for input character case. It could be extended to translate whole sentences etc - but that would need a lot of thinking to take care of all cases of what may be input.

    ' Form1 with TextBox1,
    ' TexBox2 and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim MyDict As New Dictionary(Of String, String)
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' set uo the dictionary
        ' this would likely be loaded
        ' from a file - here it is just
        ' manually done (a few only)
        With MyDict
          .Add("A", "Ba")
          .Add("B", "Ca")
          .Add("C", "Fa")
          .Add("D", "Da")
          .Add("E", "Sa")
        End With
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
          TextBox2.Text = MyDict(TextBox1.Text)
        Catch ex As KeyNotFoundException
          MessageBox.Show("That can't be translated")
          TextBox1.Text = Nothing
        End Try
      End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, June 29, 2018 1:33 AM forgot to add code
    • Marked as answer by Jakob60124 Friday, June 29, 2018 2:11 AM
    Friday, June 29, 2018 1:32 AM
  • I was working on my own language and decided to create a translator.

    This is a very complex task.  You can get an overview of some of the procedures that will be required from this project:
    https://www.codeproject.com/Articles/100126/Develop-Your-Own-Language-Translation-System

    • Marked as answer by Jakob60124 Friday, June 29, 2018 2:11 AM
    Friday, June 29, 2018 1:34 AM
  • To start off, this would be a very ambitious undertaking. The all known language translators such as Microsoft Translator API work off known languages. 

    If you truly want to do this read the following https://linuxgazette.net/152/oregan.html


    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

    • Marked as answer by Jakob60124 Friday, June 29, 2018 2:11 AM
    Friday, June 29, 2018 1:35 AM

All replies

  • Hi

    From your description, I think you could try with a Dictionary(Of String, String).

    With such a Dictionary, an entry in TextBox1 as the Index into the Dictionary would return the Translation.

    here is some very very basic code to show the bare bones of what I mean above. There is no provisions for input character case. It could be extended to translate whole sentences etc - but that would need a lot of thinking to take care of all cases of what may be input.

    ' Form1 with TextBox1,
    ' TexBox2 and Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Dim MyDict As New Dictionary(Of String, String)
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' set uo the dictionary
        ' this would likely be loaded
        ' from a file - here it is just
        ' manually done (a few only)
        With MyDict
          .Add("A", "Ba")
          .Add("B", "Ca")
          .Add("C", "Fa")
          .Add("D", "Da")
          .Add("E", "Sa")
        End With
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
          TextBox2.Text = MyDict(TextBox1.Text)
        Catch ex As KeyNotFoundException
          MessageBox.Show("That can't be translated")
          TextBox1.Text = Nothing
        End Try
      End Sub
    End Class


    Regards Les, Livingston, Scotland


    • Edited by leshay Friday, June 29, 2018 1:33 AM forgot to add code
    • Marked as answer by Jakob60124 Friday, June 29, 2018 2:11 AM
    Friday, June 29, 2018 1:32 AM
  • I was working on my own language and decided to create a translator.

    This is a very complex task.  You can get an overview of some of the procedures that will be required from this project:
    https://www.codeproject.com/Articles/100126/Develop-Your-Own-Language-Translation-System

    • Marked as answer by Jakob60124 Friday, June 29, 2018 2:11 AM
    Friday, June 29, 2018 1:34 AM
  • To start off, this would be a very ambitious undertaking. The all known language translators such as Microsoft Translator API work off known languages. 

    If you truly want to do this read the following https://linuxgazette.net/152/oregan.html


    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

    • Marked as answer by Jakob60124 Friday, June 29, 2018 2:11 AM
    Friday, June 29, 2018 1:35 AM
  • Hello,

    I tried @leshay's method and it works. The only problem is that it only translates one character at a time. 

    Thanks

    • Edited by Jakob60124 Friday, June 29, 2018 2:34 AM It works now. I set the (String, String) to (String, Integer), and then used a conversion to convert them back. I just saw that your method does work as well.
    Friday, June 29, 2018 2:24 AM
  • Hello,

    I tried @leshay's method and it works. The only problem is that it only translates one character at a time. 

    Thanks

    Hi

    Yes, that is what it was made to do. As I said, it could be extended to do full phrases etc.

    You original question has been answered. I suggest you start a new thread with the new question and show all the code you have so far.


    Regards Les, Livingston, Scotland

    Friday, June 29, 2018 12:23 PM
  • Hello,

    I tried @leshay's method and it works. The only problem is that it only translates one character at a time. 

    Thanks

    Perhaps a look at a Caesar Cipher might be along the path of what you want.

    See the following for description and simple example.


    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

    Friday, June 29, 2018 12:41 PM