sublime-text-i18n-rails
sublime-text-i18n-rails copied to clipboard
Yaml formatting
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
Any news on this? Would be really nice to keep order and format of yaml file.
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.
Is it possible to add setting for quotes and pass it to yaml.dump (according this comment on SO)?
Doh, it won't help as PyYAML will wrap keys with quotes too :(
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
That's a problem :( Maybe we can add a custom dumper class? I don't have enough skills in Python :(
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!
Any thought about just shelling out to ruby to reformat the document?
@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?
Actually with the addition of #14 I'm no longer worried about this.
@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?
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.