pseudo_l10n 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/push_gem.yml +36 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +35 -0
- data/.ruby-version +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +91 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/pseudo_l10n/backend.rb +51 -0
- data/lib/pseudo_l10n/transformer.rb +50 -0
- data/lib/pseudo_l10n/version.rb +3 -0
- data/lib/pseudo_l10n.rb +22 -0
- data/pseudo_l10n.gemspec +42 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9c57ea9e349e911eb327be71d880ff488f1c11aeb30f9d8bde8c8250886e10cd
|
4
|
+
data.tar.gz: ef641dcd92862f2c632a5f08ac5a5805223f5b3f913ea9e5a463d18f286ebe9f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 72061e39781fcaf8e84ca349d4d51e7fec06a4ab700bcc653705e2d3506c3aef8d79d10ff1da7f02164ec9d7349990ae14125e0bb26fe1b974a81aa014680f3b
|
7
|
+
data.tar.gz: d4d774c505da06be2b6a4273c5c357968776f20b3a18d7be80f1ebb1cbf82599300b80b12f5fef1295266a1b42cc4a06af961d682752d7ddf4fc06a8938d6fdd
|
@@ -0,0 +1,36 @@
|
|
1
|
+
name: Push Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags:
|
6
|
+
- v*
|
7
|
+
|
8
|
+
permissions:
|
9
|
+
contents: read
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
push:
|
13
|
+
if: github.repository == 'aergonaut/pseudo_l10n'
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
|
16
|
+
permissions:
|
17
|
+
contents: write
|
18
|
+
id-token: write
|
19
|
+
|
20
|
+
steps:
|
21
|
+
# Set up
|
22
|
+
- name: Harden Runner
|
23
|
+
uses: step-security/harden-runner@v2.8.1
|
24
|
+
with:
|
25
|
+
egress-policy: audit
|
26
|
+
|
27
|
+
- uses: actions/checkout@v4
|
28
|
+
|
29
|
+
- name: Set up Ruby
|
30
|
+
uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
bundler-cache: true
|
33
|
+
ruby-version: ruby
|
34
|
+
|
35
|
+
# Release
|
36
|
+
- uses: rubygems/release-gem@v1
|
@@ -0,0 +1,28 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "main" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "main" ]
|
8
|
+
|
9
|
+
permissions:
|
10
|
+
contents: read
|
11
|
+
|
12
|
+
jobs:
|
13
|
+
test:
|
14
|
+
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
strategy:
|
17
|
+
matrix:
|
18
|
+
ruby-version: ['3.1', '3.2', '3.3']
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v4
|
22
|
+
- name: Set up Ruby
|
23
|
+
uses: ruby/setup-ruby@v1
|
24
|
+
with:
|
25
|
+
ruby-version: ${{ matrix.ruby-version }}
|
26
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
27
|
+
- name: Run tests
|
28
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# We want Exclude directives from different
|
2
|
+
# config files to get merged, not overwritten
|
3
|
+
inherit_mode:
|
4
|
+
merge:
|
5
|
+
- Exclude
|
6
|
+
|
7
|
+
require:
|
8
|
+
# Standard's config uses custom cops,
|
9
|
+
# so it must be loaded along with custom Standard gems
|
10
|
+
- standard
|
11
|
+
- standard-custom
|
12
|
+
- standard-performance
|
13
|
+
# rubocop-performance is required when using Performance cops
|
14
|
+
- rubocop-performance
|
15
|
+
|
16
|
+
inherit_gem:
|
17
|
+
standard: config/base.yml
|
18
|
+
# You can also choose a Ruby-version-specific config
|
19
|
+
# standard: config/ruby-3.0.yml
|
20
|
+
# Standard plugins must be loaded separately (since v1.28.0)
|
21
|
+
standard-performance: config/base.yml
|
22
|
+
standard-custom: config/base.yml
|
23
|
+
|
24
|
+
# Sometimes we enable metrics cops
|
25
|
+
# (which are disabled in Standard by default)
|
26
|
+
#
|
27
|
+
# Metrics:
|
28
|
+
# Enabled: true
|
29
|
+
|
30
|
+
# Global options, like Ruby version
|
31
|
+
AllCops:
|
32
|
+
SuggestExtensions: false
|
33
|
+
|
34
|
+
Style/ArgumentsForwarding:
|
35
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.1
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at aergonaut@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in pseudo_l10n.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem "rubocop"
|
10
|
+
gem "standard", "~> 1.39", require: false
|
11
|
+
gem "syntax_tree"
|
12
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pseudo_l10n (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
concurrent-ruby (1.1.10)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
i18n (1.12.0)
|
13
|
+
concurrent-ruby (~> 1.0)
|
14
|
+
json (2.7.2)
|
15
|
+
language_server-protocol (3.17.0.3)
|
16
|
+
lint_roller (1.1.0)
|
17
|
+
parallel (1.25.1)
|
18
|
+
parser (3.3.3.0)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
racc
|
21
|
+
prettier_print (1.2.1)
|
22
|
+
racc (1.8.0)
|
23
|
+
rainbow (3.1.1)
|
24
|
+
rake (13.2.1)
|
25
|
+
regexp_parser (2.9.2)
|
26
|
+
rexml (3.3.1)
|
27
|
+
strscan
|
28
|
+
rspec (3.12.0)
|
29
|
+
rspec-core (~> 3.12.0)
|
30
|
+
rspec-expectations (~> 3.12.0)
|
31
|
+
rspec-mocks (~> 3.12.0)
|
32
|
+
rspec-core (3.12.0)
|
33
|
+
rspec-support (~> 3.12.0)
|
34
|
+
rspec-expectations (3.12.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.12.0)
|
37
|
+
rspec-mocks (3.12.0)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.12.0)
|
40
|
+
rspec-support (3.12.0)
|
41
|
+
rubocop (1.64.1)
|
42
|
+
json (~> 2.3)
|
43
|
+
language_server-protocol (>= 3.17.0)
|
44
|
+
parallel (~> 1.10)
|
45
|
+
parser (>= 3.3.0.2)
|
46
|
+
rainbow (>= 2.2.2, < 4.0)
|
47
|
+
regexp_parser (>= 1.8, < 3.0)
|
48
|
+
rexml (>= 3.2.5, < 4.0)
|
49
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
50
|
+
ruby-progressbar (~> 1.7)
|
51
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
52
|
+
rubocop-ast (1.31.3)
|
53
|
+
parser (>= 3.3.1.0)
|
54
|
+
rubocop-performance (1.21.1)
|
55
|
+
rubocop (>= 1.48.1, < 2.0)
|
56
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
57
|
+
ruby-progressbar (1.13.0)
|
58
|
+
standard (1.39.0)
|
59
|
+
language_server-protocol (~> 3.17.0.2)
|
60
|
+
lint_roller (~> 1.0)
|
61
|
+
rubocop (~> 1.64.0)
|
62
|
+
standard-custom (~> 1.0.0)
|
63
|
+
standard-performance (~> 1.4)
|
64
|
+
standard-custom (1.0.2)
|
65
|
+
lint_roller (~> 1.0)
|
66
|
+
rubocop (~> 1.50)
|
67
|
+
standard-performance (1.4.0)
|
68
|
+
lint_roller (~> 1.1)
|
69
|
+
rubocop-performance (~> 1.21.0)
|
70
|
+
strscan (3.1.0)
|
71
|
+
syntax_tree (6.2.0)
|
72
|
+
prettier_print (>= 1.2.0)
|
73
|
+
unicode-display_width (2.5.0)
|
74
|
+
|
75
|
+
PLATFORMS
|
76
|
+
arm64-darwin-23
|
77
|
+
x86_64-darwin-21
|
78
|
+
x86_64-linux
|
79
|
+
|
80
|
+
DEPENDENCIES
|
81
|
+
bundler (~> 2)
|
82
|
+
i18n (>= 1.12)
|
83
|
+
pseudo_l10n!
|
84
|
+
rake (~> 13.0)
|
85
|
+
rspec (~> 3.0)
|
86
|
+
rubocop
|
87
|
+
standard (~> 1.39)
|
88
|
+
syntax_tree
|
89
|
+
|
90
|
+
BUNDLED WITH
|
91
|
+
2.3.21
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Chris Fung
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# `PseudoL10n`
|
2
|
+
|
3
|
+
`PseudoL10n` is a simple gem to add pseudolocalization to Ruby projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'pseudo_l10n'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install pseudo_l10n
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Integration with `I18n`
|
24
|
+
|
25
|
+
This gem provides a `PseudoL10n::Backend` class that is compatible with the `i18n` gem to provide automatic pseudolocalization to your project.
|
26
|
+
|
27
|
+
To use the backend, wrap your existing `I18n.backend` with the `Backend` class from this gem:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
I18n.backend = PseudoL10n::Backend.new(I18n.backend)
|
31
|
+
```
|
32
|
+
|
33
|
+
### Pseudo-Locale
|
34
|
+
|
35
|
+
This gem generates a pseudo-locale at runtime by applying varius transformations to strings from the source locale. By
|
36
|
+
default the source locale is `:en`. You may change the source locale by setting `PseudoL10n.source_locale` to a
|
37
|
+
different value:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
PseudoL10n.source_locale = :de
|
41
|
+
```
|
42
|
+
|
43
|
+
To activate pseudolocalization, set the current `I18n.locale` to the special pseudolocale code. By default, this code is
|
44
|
+
the `source_locale` code with `-ZZ` appended. For example, the pseudo-locale code for `:de` would be `de-ZZ`. You may change the pseudo-locale code by setting `PseudoL10n.pseudo_locale` to a different value:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
PseudoL10n.pseudo_locale = :qps
|
48
|
+
```
|
49
|
+
|
50
|
+
### Low-level Transformer API
|
51
|
+
|
52
|
+
This gem also provides a low-level transformer API. This can be used to transform a string according to pseudolocale rules.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
message = "Hello world"
|
56
|
+
|
57
|
+
PseudoL10n::Transformer.call(message)
|
58
|
+
# => "√Hello world√"
|
59
|
+
```
|
60
|
+
|
61
|
+
## Development
|
62
|
+
|
63
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
64
|
+
|
65
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/pseudo_l10n. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
70
|
+
|
71
|
+
## License
|
72
|
+
|
73
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
74
|
+
|
75
|
+
## Code of Conduct
|
76
|
+
|
77
|
+
Everyone interacting in the PseudoL10n project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pseudo_l10n/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "pseudo_l10n"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module PseudoL10n
|
2
|
+
class Backend
|
3
|
+
attr_reader :original_backend
|
4
|
+
|
5
|
+
def initialize(original_backend)
|
6
|
+
@original_backend = original_backend
|
7
|
+
end
|
8
|
+
|
9
|
+
def method_missing(name, *args, &block)
|
10
|
+
if respond_to_missing?(name)
|
11
|
+
original_backend.public_send(name, *args, &block)
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def respond_to_missing?(name, include_private = false)
|
18
|
+
original_backend.respond_to?(name) || super
|
19
|
+
end
|
20
|
+
|
21
|
+
def translate(locale, key, options)
|
22
|
+
if locale.to_sym == PseudoL10n.pseudo_locale
|
23
|
+
locale = PseudoL10n.source_locale
|
24
|
+
original = original_backend.translate(locale, key, options)
|
25
|
+
::PseudoL10n::Transformer.call(original)
|
26
|
+
else
|
27
|
+
original_backend.translate(locale, key, options)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def translations
|
32
|
+
original = original_backend.translations
|
33
|
+
source_translations = original[PseudoL10n.source_locale] || {}
|
34
|
+
original[PseudoL10n.pseudo_locale] = ::PseudoL10n::Transformer.call(
|
35
|
+
source_translations
|
36
|
+
)
|
37
|
+
original
|
38
|
+
end
|
39
|
+
|
40
|
+
def available_locales
|
41
|
+
available = original_backend.available_locales
|
42
|
+
available << PseudoL10n.pseudo_locale
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def init_translations
|
48
|
+
original_backend.send(:init_translations)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PseudoL10n
|
4
|
+
module Transformer
|
5
|
+
module_function
|
6
|
+
|
7
|
+
MARKER = "√"
|
8
|
+
TEMPLATE = "%{marker}%{msg}%{marker}"
|
9
|
+
|
10
|
+
ESCAPE_PATTERN =
|
11
|
+
Regexp.new(
|
12
|
+
"(#{
|
13
|
+
["<.*?>", "{{.*?}}", "%{.*?}", "https?://\\S+", "&\\S*?;"].join("|")
|
14
|
+
})"
|
15
|
+
)
|
16
|
+
|
17
|
+
def call(original)
|
18
|
+
if original.is_a?(Hash)
|
19
|
+
original.transform_values { |value| call(value) }
|
20
|
+
elsif original.is_a?(Array)
|
21
|
+
original.map { |value| call(value) }
|
22
|
+
elsif original.is_a?(String)
|
23
|
+
result = original
|
24
|
+
result = lengthen_string(result)
|
25
|
+
mark_string(result)
|
26
|
+
else
|
27
|
+
original
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def mark_string(string)
|
32
|
+
format(TEMPLATE, marker: MARKER, msg: string)
|
33
|
+
end
|
34
|
+
|
35
|
+
def lengthen_string(string)
|
36
|
+
parts =
|
37
|
+
string
|
38
|
+
.split(ESCAPE_PATTERN)
|
39
|
+
.map do |part|
|
40
|
+
part.match?(ESCAPE_PATTERN) ? part : half_to_full_width(part)
|
41
|
+
end
|
42
|
+
|
43
|
+
parts.join
|
44
|
+
end
|
45
|
+
|
46
|
+
def half_to_full_width(string)
|
47
|
+
string.tr("0-9a-zA-Z", "0-9a-zA-Z")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/pseudo_l10n.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "pseudo_l10n/version"
|
2
|
+
|
3
|
+
module PseudoL10n
|
4
|
+
def self.pseudo_locale=(locale)
|
5
|
+
@pseudo_locale = locale&.to_sym
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.pseudo_locale
|
9
|
+
@pseudo_locale || :"#{source_locale}-ZZ"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.source_locale=(locale)
|
13
|
+
@source_locale = locale&.to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.source_locale
|
17
|
+
@source_locale || :en
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require "pseudo_l10n/transformer"
|
22
|
+
require "pseudo_l10n/backend"
|
data/pseudo_l10n.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "pseudo_l10n/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "pseudo_l10n"
|
7
|
+
spec.version = PseudoL10n::VERSION
|
8
|
+
spec.authors = ["Chris Fung"]
|
9
|
+
spec.email = ["aergonaut@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Simple utility for pseudo-localization in Ruby"
|
12
|
+
spec.homepage = "https://github.com/aergonaut/pseudo_l10n"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata[
|
20
|
+
"source_code_uri"
|
21
|
+
] = "https://github.com/aergonaut/pseudo_l10n.git"
|
22
|
+
else
|
23
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
24
|
+
"public gem pushes."
|
25
|
+
end
|
26
|
+
|
27
|
+
# Specify which files should be added to the gem when it is released.
|
28
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
29
|
+
spec.files =
|
30
|
+
Dir.chdir(File.expand_path("..", __FILE__)) do
|
31
|
+
`git ls-files -z`.split("\x0")
|
32
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
33
|
+
end
|
34
|
+
spec.bindir = "exe"
|
35
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
36
|
+
spec.require_paths = ["lib"]
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 2"
|
39
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
40
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
41
|
+
spec.add_development_dependency "i18n", ">= 1.12"
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pseudo_l10n
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Fung
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: i18n
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.12'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- aergonaut@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".github/workflows/push_gem.yml"
|
77
|
+
- ".github/workflows/ruby.yml"
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".rubocop.yml"
|
81
|
+
- ".ruby-version"
|
82
|
+
- CODE_OF_CONDUCT.md
|
83
|
+
- Gemfile
|
84
|
+
- Gemfile.lock
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.md
|
87
|
+
- Rakefile
|
88
|
+
- bin/console
|
89
|
+
- bin/setup
|
90
|
+
- lib/pseudo_l10n.rb
|
91
|
+
- lib/pseudo_l10n/backend.rb
|
92
|
+
- lib/pseudo_l10n/transformer.rb
|
93
|
+
- lib/pseudo_l10n/version.rb
|
94
|
+
- pseudo_l10n.gemspec
|
95
|
+
homepage: https://github.com/aergonaut/pseudo_l10n
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata:
|
99
|
+
homepage_uri: https://github.com/aergonaut/pseudo_l10n
|
100
|
+
source_code_uri: https://github.com/aergonaut/pseudo_l10n.git
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubygems_version: 3.5.11
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Simple utility for pseudo-localization in Ruby
|
120
|
+
test_files: []
|