From 6e9dcae26c2734a8ea95eeb3af1c9c5d40361eea Mon Sep 17 00:00:00 2001 From: BernatBC Date: Mon, 15 Jan 2024 19:26:47 +0100 Subject: [PATCH] Add Translation Posts --- content/posts/translation/content/index.md | 23 ++- .../posts/translation/new-language/index.md | 162 ++++++++++++++++++ content/posts/translation/site-data/index.md | 78 ++++++++- 3 files changed, 259 insertions(+), 4 deletions(-) create mode 100644 content/posts/translation/new-language/index.md diff --git a/content/posts/translation/content/index.md b/content/posts/translation/content/index.md index 6033dbd7..cbbeba15 100644 --- a/content/posts/translation/content/index.md +++ b/content/posts/translation/content/index.md @@ -1,6 +1,9 @@ --- title: "How to Translate Posts" -date: 2020-06-07T06:20:50+06:00 +date: 2024-01-15T06:20:50+06:00 +author: + name: BernatBC + image: images/author/bernatbc.png menu: sidebar: name: Translating Posts @@ -9,4 +12,20 @@ menu: weight: 520 --- -## Coming soon....... +This theme has built-in support for multiple language. + +Before starting the post translation, make sure that you have enabled the language to your site. If that's not the case, you can follow the section `Add the language to the site` from the guide [How to Translate Site Data](/posts/translation/site-data/). + +## Creating the post + +Once you have your desired language added to your website, know you can translate posts to that language. We're going to assume that you want to translate an existing post. + +### Create the index file + +The first step is to locate the `index.md` file from the post that you want to translate. Then you have to create a file in the same directory (or you can just copy the `index.md` file), and name it `index..md`, where `` is the language code that you can find in the language table in [How to Translate Site Data](/posts/translation/site-data/). + +### Translate the post + +Now, you can start translating the post, the same way as you write a new post. + +> INFO: If you're dealing with internal references, you'll need to add the prefix `/` in front of your relative path. For example, if you want to create a link that is pointing to `/posts/translation/site-data/`, the link for the translated post will be `//posts/translation/site-data/`. diff --git a/content/posts/translation/new-language/index.md b/content/posts/translation/new-language/index.md new file mode 100644 index 00000000..aaccd669 --- /dev/null +++ b/content/posts/translation/new-language/index.md @@ -0,0 +1,162 @@ +--- +title: "How to add an unsupported language" +date: 2024-01-15T06:20:50+06:00 +author: + name: BernatBC + image: images/author/bernatbc.png +menu: + sidebar: + name: Adding new language + identifier: new-language + parent: translation + weight: 510 +--- + +If you want to translate to an unsupported language, you can translate the UI elements. + +## Create an `i18n` file. + +To do so, you have to create the `i18n` diretory inside the root of the site, the directory where you can find the `config.yaml` file, and directories like `data`, `content`, etc. + +Afterwards, you can create the file `.toml` into the `i18n` directory. In this [directory](https://github.com/hugo-toha/hugo-toha.github.io/tree/gh-pages/flags/1x1), you can find all language codes with the flag that will appear with that code. + +## Translate the UI elements. + +Inside the new file, just copy the following content, and replace the content between the quotation marks with the name in your desired language. + +{{< alert type="warning" >}} +If the content above gets obsolete, you can copy the contents from the [en](https://github.com/hugo-toha/toha/blob/main/i18n/en.toml) file. +{{< /alert >}} + +```toml +# More documentation here: https://github.com/nicksnyder/go-i18n +[home] +other = "Home" + +[posts] +other = "Posts" + +[toc_heading] +other = "Table of Contents" + +[tags] +other = "Tags" + +[categories] +other = "Categories" + +[at] +other = "at" + +[resume] +other = "My resume" + +[navigation] +other = "Navigation" + +[contact_me] +other = "Contact me:" + +[email] +other = "Email" + +[phone] +other = "Phone" + +[newsletter_text] +other = "Stay up to date with email notification" + +[newsletter_input_placeholder] +other = "Enter email" + +[newsletter_warning] +other = "By entering your email address, you agree to receive the newsletter of this website." + +[submit] +other = "Submit" + +[hugoAttributionText] +other = "Powered by" + +[prev] +other = "Prev" + +[next] +other = "Next" + +[share_on] +other = "Share on" + +[improve_this_page] +other = "Improve this page" + +[out_of] +other = "out of" + +[publications] +other = "Publications" + +[taken_courses] +other = "Taken Courses" + +[course_name] +other = "Course Name" + +[total_credit] +other = "Total Credit" + +[obtained_credit] +other = "Obtained Credit" + +[extracurricular_activities] +other = "Extracurricular Activities" + +[show_more] +other = "Show More" + +[show_less] +other = "Show Less" + +[responsibilities] +other = "Responsibilities:" + +[present] +other = "Present" + +[comments_javascript] +other = "Please enable JavaScript to view the" + +[comments_by] +other = "comments powered by" + +[read] +other = "Read" + +[project_star] +other = "Star" + +[project_details] +other = "Details" + +[err_404] +other = "The page you are looking for is not there yet." + +[more] +other = "More" + +[view_certificate] +other = "View Certificate" + +[notes] +other = "Notes" + +[disclaimer_text] +other = "Liability Notice" + +[search] +other = "Search" + +[minute] +one = "minute" +other = "minutes" +``` diff --git a/content/posts/translation/site-data/index.md b/content/posts/translation/site-data/index.md index 91625803..660c1513 100644 --- a/content/posts/translation/site-data/index.md +++ b/content/posts/translation/site-data/index.md @@ -1,6 +1,9 @@ --- title: "How to Translate Site Data" -date: 2020-06-07T06:20:50+06:00 +date: 2024-01-15T06:20:50+06:00 +author: + name: BernatBC + image: images/author/bernatbc.png menu: sidebar: name: Translating Homepage @@ -9,4 +12,75 @@ menu: weight: 510 --- -## Coming soon....... +This theme has built-in support for multiple language. + +## Add the language to the site + +Adding the language to your site will translate the UI to that language (e.g. the buttons, the nav bars, etc.). + +### Get language code + +In order to translate your site, you will need the code from your language. The following table contains the supported languages algonside its codes: + +| Languages | Code | +|----------------------|-------------------| +| English | `en` / none | +| বাংলা | `bn` | +| Français | `fr` | +| Indonesian | `id` | +| Deutsch | `de` | +| Español | `es` | +| 简体中文 | `zh-cn` / `zh-tw` | +| हिन्दी | `hi` | +| Italiano | `it` | +| 日本語 | `jp` | +| 한국어 | `ko` | +| русский | `ru` | +| suomi | `fi` | +| Tiếng Việt | `vn` | +| Turkish | `tr` | +| Arabic (العربية) | `ar` | +| Português Europeu | `pt-pt` | +| Català | `ad` | +| Português Brasileiro | `pt-br` | +| Dutch | `nl` | + +
+ +For a complete list of the supported languages, please check the README file from the [toha repository](https://github.com/hugo-toha/toha). + +If the language you desire to translate the content to is not available, please check the guide [How to add an unsupported language](/posts/translation/new-language/). + +### Add the language into `config.yaml` + +After you know what's the code for the language you wish to translate your site, open `config.yaml` file, and under the `languages sections` add the following: + +```yaml +languages: + en: + languageName: English + weight: 1 + : + languageName: + weight: 2 # You can set the language order with this value + +``` + +For example, if we want to set `Frech` as the new language, the section would look similar to: + +```yaml +languages: + en: + languageName: English + weight: 1 + fr: + languageName: French + weight: 2 # You can set the language order with this value + +``` + +## Translating the Main Page + +You can translate the main page by creating a new directory into `data` directory. The name of the new directory should be ``. For example, if we want to translate it to french, we would create the `fr` directory into `data` directory. + +Afterwards you can create your usual data file like `about.yaml` or `education.yaml` files, keeping the same file structure and maintaining the same file names. Inside those files, you can just translate the content of the fields into your desired language. \ No newline at end of file