Could not load translations: Invalid trailing UTF-8 octet in YAML
Asked Answered
A

5

8

Im new to rails and trying to internationalize my app with I18n. In the locales yaml file for the spanish version im trying to set up the translations as follows:

es:
  categories: "Categorias"
  home: Inicio
  live_casino: "Casino en Vivo"
  sportsbook: Deportes

This works like a charm, but as soon as I add the accent in the spanish word like this:

categories: "Categorías"

Rails gives me the following error:

I18n::InvalidLocaleData in WelcomeController#index
can not load translations from .../config/locales/es.yml: #<Psych::SyntaxError: (.../config/locales/es.yml): invalid trailing UTF-8 octet at line 1 column 1>

Ive tried everything ive found in the web and nothing has worked please help!

Alive answered 24/3, 2014 at 14:58 Comment(0)
A
12

I opened the locale file in Notepad++ and noticed it was encoded in "UTF-8 w/o BOM".

Click on Encoding -> Convert to UTF-8 and the error went away.

Alive answered 8/6, 2014 at 19:20 Comment(3)
In case you're using Textmate – I used the same basic technique via File/Re-open With Encoding/UTF8, then saving the file. YAML load then worked. Before I changed it, the checkmark in the menu was on ISO-8859-1 (Latin 1).Overwhelm
The file that I was using was encoded in ANSI. So from Notepad++ I had to click on Encoding -> Convert to UTF-8Zohara
Same with UltraEdit. Also the error Rails reported was in a file which hadn't been touched in months and didn't actually have any translation calls in it.Hammering
B
1

Try to put the following line at the beginning of the es.yml file:

# encoding: utf-8    
Buyers answered 24/3, 2014 at 15:46 Comment(0)
S
0

Had the same error, in my case, I had : in the middle of the text, but : is functional sign so get rid of it, this can be caused by any signs that has been copied from online or ord and pasted.

Shumate answered 22/7, 2020 at 14:29 Comment(0)
K
0

I resolved the same problem while using helm upgrade command. Unfortunately, helm didn't get me exact place of the problem (showed me inexistent line), so I created from scratch a blank file and copy-pasted all of the content of the damaged file. Everything goes well after this operation.

Keele answered 19/8 at 19:41 Comment(0)
D
0

In Visual Studio 2022, I had to "Save As" "with encoding" "UTF-8" my problematic yml file.

Dialect answered 22/8 at 19:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.