September 28, 2014

Develop a Regional language translator in java

Java source code to for english to malayalam language translator

     There are many online English to malayalam translator available in internet. If you are searching for a full java source code to convert english to malayalam then please dont go through this post, this only an idea how to start working on a english to malayalam language convertor. The code here is not a complete code. Copy the code paste it in your eclipse/Net bean ide and run it.

     You can download the English to malayalam convertor jar application from the link given below.
Please provide your feedback, you can comment for any post in this blog. Genuine comments will be appreciated !!! 

     Some guys sent me alternate code through face book and gmail (probably better code) after reading the post. thanks to those guys. and i have appended all those code with those posts. so share your knowledge !

Language Translator Image
Language Translator in java

Author : +belazy


/**
* Developing for office use
*/


import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.border.Border;
import java.awt.Rectangle;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
/**
* @author True caller java *
*/
public class Translator extends JFrame {

private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTextArea typeArea = null;
private JTextArea viewArea = null;
private Translator thisClass = null;
private Mozhi mozhiObj = null;
/**
* This method initializes Typing area
*
* @return javax.swing.JButton
*/
private JTextArea getTypingArea() {
if (typeArea == null) {
typeArea = new JTextArea();
//typeArea.setBounds(new Rectangle(50, 50, 600, 600));
typeArea.setBounds(new Rectangle(30, 20, 200, 100));
Border border = BorderFactory.createLineBorder(Color.BLACK);
typeArea.setBorder(BorderFactory.createCompoundBorder(border,
BorderFactory.createEmptyBorder(10, 10, 10, 10)));
typeArea.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
//System.out.println(" Vipin C P");

}

public void keyTyped(KeyEvent e) {
//System.out.println(" Developing language Translator ");
//String engWord = typeArea.getText();
//viewArea.setText(mozhiObj.getMalayalam(engWord));
viewArea.setText(convertToMalayalam(typeArea.getText()));
}
public void keyPressed(KeyEvent e) {
//System.out.println(" English to south indian language translation ");
}
});
}
return typeArea;
}
protected String convertToMalayalam(String engWord) {
String englishWord = engWord;
String malWord = englishWord.replaceAll("A", "¦");
malWord = malWord.replaceAll("bi", "Ìß");
malWord = malWord.replaceAll("the", "çÄ");
malWord = malWord.replaceAll("sh", "×í");
return malWord;
}

/**
* This method initializes Typing area
*
* @return javax.swing.JButton
*/
private JTextArea getViewArea() {
if (viewArea == null) {
viewArea = new JTextArea();
Font malFont = new Font("Kerala", Font.PLAIN, 15);
Border border = BorderFactory.createLineBorder(Color.GRAY);
viewArea.setBorder(BorderFactory.createCompoundBorder(border,
BorderFactory.createEmptyBorder(10, 10, 10, 10)));
//viewArea.setBounds(new Rectangle(700, 50, 600, 600));
viewArea.setBounds(new Rectangle(250, 20, 200, 100));
viewArea.setEditable(false);
viewArea.setFont(malFont);
}
return viewArea;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Translator thisClass = new Translator();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}

/**
* This is the default constructor
*/
public Translator() {
super();
initialize();
}

/**
* This method initializes this
*
* @return void
*/
private void initialize() {
//this.setSize(1340, 720);
this.setSize(500, 200);
this.setContentPane(getJContentPane());
this.setTitle("CFED : English To Malayalam Translator");
mozhiObj = new Mozhi();
}

/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(null);
//jContentPane.add(getLoginButton(), null);
jContentPane.add(getTypingArea(), null);
jContentPane.add(getViewArea(), null);
}
return jContentPane;
}

}






function : convertToMalayalam() is that converts english words to malayalam, work on it. you can use a separate class to do the job.


You can download the malayalam font from this link
FileName : Javabelazy72902
Pasword : independenceday

Please try this code and feedback...

here is an online malayalam editor link


Thanks to +deepajayaprakash payyanakkal


http://javabelazy.blogspot.in/

Facebook comments