Dotstrings
A parser for Apple strings files (.strings) written in Ruby.
Install / Use
/learn @raymondjavaxx/DotstringsREADME
DotStrings
A parser for Apple strings files (.strings) written in Ruby. Some of the features of DotStrings include:
- A fast and memory-efficient streaming parser.
- Support for multiline (
/* ... */) comments as well as single-line comments (// ...). - An API for creating strings files programmatically.
- Handles Unicode and escaped characters.
- Helpful error messages: know which line and column fail to parse and why.
- Well tested and documented.
Installing
You can install DotStrings manually by running:
$ gem install dotstrings
Or by adding the following entry to your Gemfile, then running $ bundle install.
gem 'dotstrings'
Usage
You can load .strings files using the DotString.parse() utility method. This method returns a DotStrings::File object or raises an exception if the file cannot be parsed.
file = DotStrings.parse_file('en-US/Localizable.strings')
file.items.each do |item|
puts item.comment
puts item.key
puts item.value
end
Strict Mode
By default, the parser runs in strict mode. This means that it will raise a DotStrings::ParsingError if it encounters comments that are not tied to a key-value pair. For example, the following file will raise an error because the first comment is not followed by a key-value pair:
/* Spanish localizations */
/* Title for a button for accepting something */
"Accept" = "Aceptar";
In strict mode, the parser will also raise an error if it encounters escaped characters that don't need to be escaped. For example, the following file will raise an error because the ? character doesn't need to be escaped:
/* Confirmation message */
"Are you sure\?" = "¿Estás seguro\?";
If you want to disable strict mode, you can pass strict: false to the DotStrings.parse_file() method. This will match the behavior of Apple's own parser, which is more lenient.
file = DotStrings.parse_file('es-ES/Localizable.strings', strict: false)
Examples
Accessing items by key
puts file['key 1'].value
# => "value 1"
Deleting items by key
file.delete('key 1')
Appending items
file << DotStrings::Item(
comment: 'Title for the cancel button',
key: 'button.cancel.title',
value: 'Cancel'
)
Saving a file
File.write('en-US/Localizable.strings', file.to_s)
For more examples, consult the documentation or the test suite.
Related Skills
node-connect
351.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
