---
title: "Introduction to ecce"
author: "[Xinyuan Chu](https://cxy.rbind.io/)"
date: "`r Sys.Date()`"
output:
  rmarkdown::html_vignette:
    number_sections: no
    toc: yes
classoption: "hyperref,"
vignette: >
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteIndexEntry{Introduction to ecce}
  %\VignetteEncoding{UTF-8}
---

## Introduction

The goal of ecce is to make it easy to translate English sentence into Chinese, or translate Chinese sentence into English. It also support browse translation results in website. In addition, also support obtain the pinyin of the Chinese character, so that you can more easily understand the pronunciation of the Chinese character.

```{r, eval = FALSE}
# Install development version from GitLab
remotes::install_gitlab("chuxinyuan/ecce")
# Install from CRAN
install.packages("ecce")
```

## Configure the ID and PASSWORD for the Youdao API

To use the ecce package, users need to first register with the [Youdao Wisdom Cloud AI open platform](https://ai.youdao.com/), and then open the text translation application.
Then put your Youdao API ID and PASSWORD in the following code and run it once.

```{r, eval=FALSE}
if (!file.exists("~/.Renviron")){
  file.create("~/.Renviron")
} 

file_path = "~/.Renviron"
file = file(file_path, open = "a")

comment = "# ID and PASSWORD of Youdao Translation"
writeLines(comment, file)

code_lines = c(
  "app_key = \"Your Youdao API ID\"",
  "app_secret = \"Your Youdao API PASSWORD\""
)

for (code in code_lines) {
  writeLines(code, file)
}

close(file)
```

## Basic usage

By default, the from and to parameter values are set to "auto", which translate English into Chinese, or Chinese into English. Sometimes you need to explicitly specify the from and to values as "en" or "zh-CHS".

The code for each language can be found in the [Youdao Text Translation API documentation](https://ai.youdao.com/DOCSIRMA/html/trans/api/wbfy/index.html).

```{r, eval = FALSE}
# Example-1
translate("我喜欢中国")

# Example-2
translate("I like China")

# Example-3
translate(
  input = "quarto", 
  from = "en", 
  to = "zh-CHS"
)
```

## Browse translate results in website

```{r, eval = FALSE}
# Example-4
translate_view("我喜欢中国")

# Example-5
translate_view("I like China")

# Example-6
translate_view(
  input = "quarto", 
  from = "en", 
  to = "zh-CHS"
)
```

## Obtain and label Chinese pinyin

```{r, eval = FALSE}
# Example-7
pinyin("时间序列模型")
```
