Search code examples
cssruby-on-railsrubylocaleyaml

Format Strings in YML Files


  1. Im using a YML file for language conversion and i cant figure out how to format text within this file. For instance if i say

    #fourthScreenFive: "В this is string 1 \n this is string 2"

the \n does not work. Would anyone know how i can get this done?

  1. I also want to be able to center some strings and again /t or any other command doesn't work. Would anyone have any documentation?

I found this : http://www.yaml.org/YAML_for_ruby.html#three_trailing_newlines_in_literals but it doesnt have much information on strings that are already strings " ".

 fourthScreenSeven: |+     
                 Оно оказалось настолько вкусным что с тех,      
                 пор мы никогда не меняли рецепт 

Solution

  • To add extra lines in a string using YAML you could use a yaml like that:

    fourthScreenSeven: |
      Оно оказалось настолько вкусным что с тех,
      пор мы никогда не меняли рецепт
    
    fourthScreenFive: |
      В this is string 1
      this is string 2
    

    Using the following ruby code:

    p YAML.load(IO.read('yaml.yml'))
    

    You will get this result:

    {"fourthScreenSeven"=>
        "Оно оказалось настолько вкусным что с тех,\nпор мы никогда не меняли рецепт\n",
        "fourthScreenFive"=>"В this is string 1\nthis is string 2\n"}