Skip to content

Isalin is a spring-boot library that aims to provide a less boilerplate and convenient way of using the Google translate API.

License

Notifications You must be signed in to change notification settings

acltabontabon/isalin

Repository files navigation

Isalin

isalin-version isalin-java-comp isalin-spring-comp isalin-license CodeQL Dependency Review

Isalin is a spring-boot library that aims to provide a less boilerplate and convenient way of using the Google translate API.

Features

  • 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

Usage

Setting Up Your Project

Apache Maven
<dependency>
    <groupId>com.acltabontabon</groupId>
    <artifactId>isalin</artifactId>
    <version>1.0.1</version>
</dependency>
Gradle
implementation group: 'com.acltabontabon', name: 'isalin', version: '1.0.1'

Using @Translate

To start using Isalin library, you need to setup first your Google Authentication credentials.

Single text translation

@Translate(from = Language.ENGLISH, to = Language.FILIPINO)
public String getGreetings() {
  return "Hello world!";
}

Single text translation with auto detection of source language

@Translate(to = Language.FILIPINO)
public String getGreeting() {
  return "Hello world!";
}

Single text translation within a custom object

@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;
}

Multiple text translation

@Translate(from = Language.ENGLISH, to = Language.FILIPINO)
public List<String> getGreetings() {
  return List.of("Hello!", "Hi");
}

Single file translation

@Translate(from = Language.ENGLISH, to = Language.FILIPINO)
public File getDocument() {
  return new File("/path/to/my/file.pdf");
}

Note Supported file formats: .doc, .docx, .pdf, .ppt, .pptx, .xls, .xlsx

Multiple file translation

@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"));
}

Inline translation

@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);
}

Motivation

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. 😁 ☕

Buy Me a Coffee at ko-fi.com

Request / Issues

For feature request or found an issues please open a ticket.