Isalin is a spring-boot library that aims to provide a less boilerplate and convenient way of using the Google translate API.
- Text translation
- Document translation
- Provides
@Translate
annotation to translate the response of a method - Provides spring bean named
IsalinService
for in-line usage - Supported all languages listed here
- Works with Google SDK V3
<dependency>
<groupId>com.acltabontabon</groupId>
<artifactId>isalin</artifactId>
<version>1.0.1</version>
</dependency>
implementation group: 'com.acltabontabon', name: 'isalin', version: '1.0.1'
To start using Isalin library, you need to setup first your Google Authentication credentials.
@Translate(from = Language.ENGLISH, to = Language.FILIPINO)
public String getGreetings() {
return "Hello world!";
}
@Translate(to = Language.FILIPINO)
public String getGreeting() {
return "Hello world!";
}
@Translate(value = "$.body.content", from = Language.ENGLISH, to = Language.FILIPINO)
public CustomMessage getGreeting() {
CustomMessage msg = new CustomMessage();
msg.setSource("Tarzan");
msg.setBody(new Content("Welcome to the jungle!"));
return msg;
}
@Translate(from = Language.ENGLISH, to = Language.FILIPINO)
public List<String> getGreetings() {
return List.of("Hello!", "Hi");
}
@Translate(from = Language.ENGLISH, to = Language.FILIPINO)
public File getDocument() {
return new File("/path/to/my/file.pdf");
}
Note Supported file formats:
.doc
,.docx
,.ppt
,.pptx
,.xls
,.xlsx
@Translate(from = Language.ENGLISH, to = Language.FILIPINO)
public List<File> getDocuments() {
return List.of(new File("/path/to/my/file.pdf"), new File("/path/to/my/file2.pdf"));
}
@Autowired
private IsalinService isalinService;
private void translate() {
String text = isalinService.translateText("Hello", Language.ENGLISH, Language.FILIPINO);
List<String> texts = isalinService.translateTexts(List.of("Hi","Hello"), Language.ENGLISH, Language.FILIPINO);
File doc = isalinService.translateDocument("/path/to/my/file.pdf", Language.ENGLISH, Language.FILIPINO);
List<File> docs = isalinService.translateDocuments(List.of("/path/file.ppt","/path/file.pdf"), Language.ENGLISH, Language.FILIPINO);
// auto detection of source language
String text2 = isalinService.translateText("Hello", Language.ANY, Language.FILIPINO);
File doc2 = isalinService.translateDocument("/path/to/my/file.pdf", Language.ANY, Language.FILIPINO);
}
Created this library for fun and learning. If you somehow find this helpful and/or useful, I'd be grateful for a cup of coffee. 😁 ☕
For feature request or found an issues please open a ticket.