symfony - Is there a tool to refactor a YAML file, order the lines, switch from dot format to indent? -


in symfony 2, using translation:update command generate translations yml files templates have defined teh translation strings.

i .yml files mixed up.

i searching tool, script refactor :

menu.home: __en.menu.home menu.projects: __en.menu.projects information.address: __en.information.address information.agent.languages.english: __en.information.agent.languages.english information.agent.languages.russian: __en.information.agent.languages.russian information.agent.name: __en.information.agent.name 

to :

information:   address: __en.information.address   agent:     languages:       english: __en.information.agent.languages.english       russian: __en.information.agent.languages.russian     name: __en.information.agent.name menu:   home: __en.menu.home   projects: __en.menu.projects 

here code snippet ask:

use symfony\component\yaml\yaml; use symfony\component\yaml\dumper; // ...  $dottedyaml = yaml::parse(file_get_contents('dotted-file.yml'));  $nestedyaml = array(); foreach ($dottedyaml $dottedkey => $value) {     $levels = explode('.', $dottedkey);     $levelyaml =& $nestedyaml;     {         $level = array_shift($levels);         if (!isset($levelyaml[$level])) {             $levelyaml[$level] = array();         }         $levelyaml =& $levelyaml[$level];     } while (count($levels));     $levelyaml = $value; }  $dumper = new dumper(); file_put_contents('nested-file.yml', $dumper->dump($nestedyaml, 5)); 

please aware though code works example if have this:

menu: "here problem" menu.home: __en.menu.home menu.projects: __en.menu.projects 

you cannot convert nested notation unless decide kind of convention if level contains scalar value , array of nested values:

menu:   home: __en.menu.home   projects: __en.menu.projects   value: "here problem" # made "value" attribute store top level value 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -