Class: I18nContextGenerator::Parsers::Base
- Inherits:
-
Object
- Object
- I18nContextGenerator::Parsers::Base
- Defined in:
- lib/i18n_context_generator/parsers/base.rb
Overview
Base class for translation file parsers
Direct Known Subclasses
AndroidXmlParser, JsonParser, StringsParser, XcstringsParser, YamlParser
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.for(path, locale: nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/i18n_context_generator/parsers/base.rb', line 16 def self.for(path, locale: nil) ext = File.extname(path).downcase case ext when '.json' JsonParser.new when '.yml', '.yaml' YamlParser.new(locale: locale) when '.strings' StringsParser.new when '.xcstrings' XcstringsParser.new when '.xml' # Check if it's an Android strings.xml raise Error, "Unsupported XML format: #{path} (only Android strings.xml is supported)" unless FileClassifier.android_translation_file?(path) AndroidXmlParser.new else raise Error, "Unsupported translation file format: #{path}" end end |
Instance Method Details
#parse(path) ⇒ Object
39 40 41 |
# File 'lib/i18n_context_generator/parsers/base.rb', line 39 def parse(path) raise NotImplementedError, 'Subclasses must implement #parse' end |