nicosantangelo / sublime-text-i18n-rails

Sublime Text 2/3 package for Rails Internationalization
MIT License
18 stars 3 forks source link

Yaml formatting #6

Open nicosantangelo opened 10 years ago

nicosantangelo commented 10 years ago

Right now, when a key is added or edited, the yaml file gets sorted in alphabetical order and quotes are deleted. For example:

From this:

en:
  test:
    new: "Bye"
    index:
      few: "Hello"

to this:

en:
  test:
    index:
      few: Hello
    new: Bye
nicosantangelo commented 10 years ago

Related StackOverflow question

atipugin commented 9 years ago

Any news on this? Would be really nice to keep order and format of yaml file.

nicosantangelo commented 9 years ago

Sadly, no, I use the package and can't add values on old projects for the same reason :(.

I have asked colleagues for help but I didn't have much luck yet.

atipugin commented 9 years ago

Is it possible to add setting for quotes and pass it to yaml.dump (according this comment on SO)?

atipugin commented 9 years ago

Doh, it won't help as PyYAML will wrap keys with quotes too :(

nicosantangelo commented 9 years ago

The problem with adding that is that the keys also get wrapped in double quotes, but adding it as a setting could be nice.

Edit: Exactly your comment :P

atipugin commented 9 years ago

That's a problem :( Maybe we can add a custom dumper class? I don't have enough skills in Python :(

nicosantangelo commented 9 years ago

I think it's the best (or only) solution. I gave it a try and didn't got very far, but this package was my first (complex) Python code, I should revisit it.

I'll let you know how it goes, but if you someone who wants to contribute, awesome!

coreymartella commented 8 years ago

Any thought about just shelling out to ruby to reformat the document?

nicosantangelo commented 8 years ago

@coreymartella I've actually never thought of that. The problem with using Ruby is that people doesn't need to have a Ruby version installed on their systems to run Sublime. Also running a ruby file from the package (Python) is a bit cumbersome.

That said, I could give it a try, did you have a specific idea on how to implement it?

coreymartella commented 8 years ago

Actually with the addition of #14 I'm no longer worried about this.

hoenth commented 6 years ago

@NicoSantangelo I know this issue has been quiet for a while, but I believe it is related to an issue I just encountered. Since many words appear at many places, I like to create a dictionary at the top of the yaml file and use anchors and references to use them throughout the file. After spending a while building out the dictionary and replacing entries with references, I used the Add Key function to add a new entry, only to find out that all of the anchors had been removed, and the references replaced with the anchored values.

Is this the default behavior of PyYaml? Do you know of anyway of not having the achors/references interpolated?

nicosantangelo commented 6 years ago

I think it's the default behavior of the lib yes. Searching around the web I found:

The anchor information in PyYAML is discarded according to the YAML 1.1 specification that PyYAML follows anchor names are a serialization detail and are discarded once composing is completed as far as I know this didn't change on YAML 1.2 :/

that said, PyYaml I might be wrong.

If you want to change the way PyYaml is used by the project you can take a look at the Yaml.py class, and more specifically to the dump here.