Class: Translations::CLI
- Inherits:
-
Thor
- Object
- Thor
- Translations::CLI
- Defined in:
- lib/translations/cli.rb
Instance Method Summary collapse
- #add(key) ⇒ Object
- #change(key) ⇒ Object
- #move(from, to) ⇒ Object
- #remove(*keys) ⇒ Object
- #translate(locale, *keys) ⇒ Object
- #update(locale, key) ⇒ Object
- #view(key) ⇒ Object
Instance Method Details
#add(key) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/translations/cli.rb', line 68 def add key translations = serializer.translations answer = ask "#{translations.master.locale}?" if answer.length > 0 translations.master[key] = answer else say "You have to provide a translation for master" return end translations.slaves.each do |translation| answer = ask "#{translation.locale}?" if answer.length > 0 translation[key] = answer end end serializer.save translations end |
#change(key) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/translations/cli.rb', line 97 def change key translations = serializer.translations say "#{translations.master.locale}: #{translations.master[key]}" answer = ask "#{translations.master.locale}?" if answer.length > 0 translations.master[key] = answer else say "You have to provide a translation for master" return end translations.slaves.each do |translation| say "#{translation.locale}: #{translation[key]}" answer = ask "#{translation.locale}?" if answer.length > 0 translation[key] = answer else translation.remove key end end serializer.save translations end |
#move(from, to) ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/translations/cli.rb', line 56 def move from, to translations = serializer.translations translations.move from, to serializer.save translations end |
#remove(*keys) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/translations/cli.rb', line 45 def remove *keys translations = serializer.translations keys.each do |key| translations.remove key end serializer.save translations end |
#translate(locale, *keys) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/translations/cli.rb', line 15 def translate locale, *keys translations = serializer.translations translation = translations.for_locale(locale) if keys.length == 0 keys = translation.missing_keys_from_translation(translations.master) end master = translations.master keys.each do |key| say key say "#{master.locale}: #{master[key]}" translations.slaves.each do |translation| answer = ask "#{translation.locale}?" if answer.length > 0 translation[key] = answer end puts serializer.save translations end end end |
#update(locale, key) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/translations/cli.rb', line 129 def update locale, key translations = serializer.translations translation = translations.for_locale(locale) say "#{locale}: #{translation[key]}" answer = ask "#{locale}?" translation[key] = answer serializer.save translations end |
#view(key) ⇒ Object
142 143 144 145 146 147 148 149 150 |
# File 'lib/translations/cli.rb', line 142 def view key serializer.translations.each do |translation| if translation.has_key? key say "#{translation.locale}: #{translation[key]}" else say "#{translation.locale} does not have key #{key}" end end end |