How to Translate YAML Files with PTC

YAML files are known for being simple to read and write, making them a popular choice for software localization. PTC (Private Translation Cloud) lets you translate YAML files quickly and easily.

YAML (YAML Ain’t Markup Language) files play an important role in frameworks like Ruby on Rails, Symfony, and Laravel. These files often contain user-facing text, such as error messages or notifications. Translating this content allows users to interact with your app in their preferred language, enhancing user experience.

With PTC, translating YAML files becomes fast and efficient. PTC provides AI-powered translations that deliver better-than-human accuracy. It also integrates directly with Git, making it easy to manage translation updates automatically.

In this tutorial, you’ll learn how to:

  • Prepare your files for translation
  • Translate YAML files into multiple languages
  • Integrate translations into your development process

Let’s start by exploring what makes YAML a great choice for localization.

Why YAML Works for Localization

YAML is a human-readable file format often used to store and organize data in applications. Its clean and simple format relies on indentation and key-value pairs to represent data. Unlike JSON, it avoids brackets and commas.

Example: Basic YAML Structure

en:
  app_name: "MyApp"
  welcome_message: "Welcome to MyApp!"
  user:
    name: "Name"
    email: "Email"
    password: "Password"
  errors:
    login_failed: "Login failed. Please try again."
    missing_fields: "Please fill out all required fields."
  notifications:
    signup_success: "Thank you for signing up!"
    account_updated: "Your account information has been updated."

The simplicity of YAML makes it accessible for both developers and non-developers. It’s a great choice for managing translation data in localization projects.

For example, Ruby on Rails uses YAML as the default format for resource files, which store translations for different languages. If you’re working with RoR, you can learn more in our step-by-step tutorial on internationalizing and translating your Ruby on Rails applications.

Preparing YAML Files for Translation

Before translating your YAML files, make sure they follow a clear structure. You don’t need major changes to the source language file, but following these best practices can help avoid issues.

Use a Consistent Key Structure

Each key should clearly represent a term or phrase in your application. When you add translations in other languages, those same keys will be used.

Example:

en: 
greeting: "Hello" 
farewell: "Goodbye"

In this example, the keys “greeting” and “farewell” stay the same in all languages. Only the values – “Hello” and “Goodbye” – will be translated.

Use Placeholders Correctly

In many apps, you’ll need placeholders to insert dynamic values like names, dates, or quantities. Placeholders get replaced with actual values when your app runs.

Example:

en:
order_confirmation: "Thank you, %{customer_name}, for your order of %{product_quantity} items!"

Here, %{customer_name} and %{product_quantity} act as placeholders. Your app will fill them with real data at runtime. You’ll maintain the same structure across all translations.

How to Translate Your YAML Files (The Easy and Free Way)

Now that you have your YAML files prepared and organized, it’s time to translate them. 

This is where PTC (Private Translation Cloud) comes in. PTC offers a Free resource file translation tool that lets you easily translate your YAML files without the need for manual work.

Here’s how it works:

  1. Upload your YAML files
  2. Choose the languages you want to translate your YAML files into
  3. Download the translation files, ready for your software
YAML file automatically translated by Free resource files translation

The best part? It’s all fast, easy, and completely free.

Managing Translations: ​​Where Do These Files Go?

In the previous step, PTC provided separate YAML files for each language. Now, you’ll need to store these files in the right location within your project.

For most setups, these files go into a dedicated locales/ folder, with each language stored in its own separate file. This structure keeps your translations organized and scalable as you add more languages or content.

Example folder structure:

locales/
en.yml
fr.yml
es.yml

In this structure:

  • locales/ is the folder where all your translation files are stored.
  • Each language (e.g., English, French, Spanish) gets its own file inside this folder.

Example content of each file:

.yml

en.yml
greeting: "Hello" 
farewell: "Goodbye"

.yml

fr.yml
greeting: "Bonjour" 
farewell: "Au revoir"

.yml

es.yml
greeting: "Hola" 
farewell: "Adiós" 

Integrating YAML File Localization Into Your Development Process

As your project evolves, you’ll likely add new text to your source language file that requires translation. You can always use PTC’s Free resource translation tool to translate and then manually upload the updated files. But there’s an easier and better way.

With a full PTC subscription, you can get better-than-human translation quality and integrate YAML file localization directly into your development workflow.

How it Works

Code Repository Integration

PTC integrates with your code repository (e.g., GitHub, GitLab) and detects the resource files that require translation.

Project Setup

In just a few clicks, you give PTC the extra project details it needs to deliver Better Than Human Translation.

Instant AI Translation

PTC automatically translates your text using AI and provides you with Better Than Human Translation. It then sends the translations to your repository as a merge request.

Automatic Detection of Changes

Whenever you work on a new feature in a branch, PTC detects and translates any new text in that branch. You can control which branches to translate.

Simplify YAML File Translation

In this guide, you’ve learned how to:

Prepare your YAML files with a consistent key structure

Use placeholders to handle dynamic content

Organize translations into separate files for each language

Use PTC’s free resource translation tool to quickly and automatically translate your YAML files

To enhance your workflow, PTC offers much more than just easy YAML file translation. With a full subscription, you’ll benefit from:

Git integration

to automatically detect and update translations with each code change

AI-powered translations

that provide better than human accuracy

Automatic translation updates

sent as merge requests directly to your repository

User-friendly interface

for managing your project’s translations easily

Per-seat pricing

with unlimited translations to support your project’s growth

By integrating PTC into your workflow, you can simplify translation management and effortlessly keep your multilingual project up to date.

Scroll to Top