---
title: "Convert an existing project"
description: >
  How to convert an existing project to a multilingual Quarto project
vignette: >
  %\VignetteIndexEntry{Convert an existing project}
  %\VignetteEngine{quarto::html}
  %\VignetteEncoding{UTF-8}
---

If you want to turn an existing project into a multilingual project, you can use {babelquarto}'s `register_main_language()` and `register_further_languages()` functions.

Let's start with a book whose main language is English.

```{r}
#| results: 'hide'
parent_dir <- withr::local_tempdir()
project_dir <- "babelbook"
quarto_bin <- quarto::quarto_path()
withr::with_dir(parent_dir, {
  sys::exec_wait(
    quarto_bin,
    args = c("create-project", project_dir, "--type", "book")
  )
})
```

First you'll need to register the main language in the Quarto configuration:

```{r}
project_path <- file.path(parent_dir, project_dir)
withr::with_dir(project_path, {
  babelquarto::register_main_language(main_language = "en")
})
```


Then you can add further languages, say Spanish and French:

```{r}
withr::with_dir(project_path, {
  babelquarto::register_further_languages(further_languages = c("es", "fr"))
})
```

The `project_path` of `register_main_language()` and `register_further_languages()` defaults to `.` so from within that project path, there's no need to specify it.

We end up with a multilingual book in English and Spanish. If you look at the `_quarto.yml` file in the project directory, you'll see that the `main_language` key is `en` and the `languages` key contains `es` and `fr`.

```{r}
#| echo: false
#| results: 'asis'

cat("```{.yaml filename='_quarto.yml'}\n")
readLines(file.path(parent_dir, project_dir, "_quarto.yml")) |>
  cat(sep = "\n")
cat("```\n")
```

You can now start translating your book into Spanish and French. Each file of you project can be translated by adding a suffix to the file name.
For example, the Spanish version of `index.md` will be in `index.es.md` and the French version in `index.fr.md`.

You will have to provide the translations yourself.
If you want to translate your multilingual project using automatic translation with DeepL, you should have a look at [babeldown](http://docs.ropensci.org/babeldown/articles/quarto.html).

## Next steps

Take a deeper dive into the configuration options available in {babelquarto} and have a look at `vignette("configuration")`.

If you want to deploy your website on continuous integration, have a look at `vignette("render-with-ci")`.

If you need to personalize the quarto templates, have a look at `vignette("custom-templates")`.
