arabic 0.1.7 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +18 -0
- data/CHANGELOG.md +83 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +53 -10
- data/Rakefile +6 -1
- data/arabic.gemspec +21 -7
- data/exe/arabic +65 -0
- data/lib/arabic/iso233.rb +60 -52
- data/lib/arabic/persian.rb +70 -0
- data/lib/arabic/urdu.rb +75 -67
- data/lib/arabic/version.rb +3 -1
- data/lib/arabic.rb +38 -10
- metadata +68 -23
- data/.gitignore +0 -8
- data/.travis.yml +0 -5
- data/Gemfile +0 -6
- data/Gemfile.lock +0 -22
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a08be5b924a8dd99c80751f0e151d1d72232c6c8a48f3b303bbc66a3534a2f87
|
|
4
|
+
data.tar.gz: 36b4ce7cff0deeae8978ca0aef18c873d4e08e650c93a211cdba7f188801b40c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 77f173afdac333ef8db23a11bb4c29b71b67bf2a3f55aa8eb4dea357d1dc19887d7ea63a18fa5492f4af99d698466ba28918d2800bf3f9a22c4d60c55bddf5df
|
|
7
|
+
data.tar.gz: 78a62f2ff52282ba5c29cdf403aa8280eb495bf1a49b330534cc15b41fddbc737a2bb30d5a288d7299a7e94636b92fd3c3ef063d08e4e425bbcf54059183ca72
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
NewCops: enable
|
|
3
|
+
SuggestExtensions: false
|
|
4
|
+
Exclude:
|
|
5
|
+
- 'bin/console'
|
|
6
|
+
- 'bin/setup'
|
|
7
|
+
- 'pkg/**/*'
|
|
8
|
+
- 'vendor/**/*'
|
|
9
|
+
- 'coverage/**/*'
|
|
10
|
+
|
|
11
|
+
Gemspec/DevelopmentDependencies:
|
|
12
|
+
EnforcedStyle: gemspec
|
|
13
|
+
|
|
14
|
+
Style/Documentation:
|
|
15
|
+
Enabled: false
|
|
16
|
+
|
|
17
|
+
Style/StringLiterals:
|
|
18
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2026-09-17
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Persian transliteration scheme (`:persian`) with full 32-letter alphabet and Persian numerals support.
|
|
14
|
+
- CLI executable `exe/arabic` supporting direct arguments, files, piped STDIN, and scheme flag (`-s`).
|
|
15
|
+
- Integration tests for CLI arguments, flags, and STDIN input.
|
|
16
|
+
- GitHub Actions CI workflow for modern Ruby versions on `main` branch with experimental `head`.
|
|
17
|
+
- Automated GitHub Actions release workflow for building and publishing gem on git tag push.
|
|
18
|
+
- Precompiled and cached regular expressions for character tables for improved performance.
|
|
19
|
+
- Case-insensitive scheme resolution (e.g. `:urdu`, `"urdu"`, `:URDU`, `:persian`).
|
|
20
|
+
- Informative `ArgumentError` when an unknown transliteration scheme is specified.
|
|
21
|
+
- Standard gem metadata URIs (`source_code_uri`, `changelog_uri`, `bug_tracker_uri`).
|
|
22
|
+
- RuboCop code style checks integrated into default `rake` task.
|
|
23
|
+
- SimpleCov code test coverage tracking with 100% line coverage.
|
|
24
|
+
- Unit tests for edge cases (nil/empty strings, scheme normalization, error handling).
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
- Update development dependencies (rubocop, rake, rdoc, irb, json, minitest).
|
|
28
|
+
- Namespaced `Urdu`, `Iso233`, and `Persian` modules under `Arabic` (`Arabic::Urdu`, `Arabic::Iso233`, `Arabic::Persian`) with backwards-compatible top-level aliases.
|
|
29
|
+
- Set minimum required Ruby version to `>= 3.3.0` in gemspec.
|
|
30
|
+
- Untrack `Gemfile.lock` and add to `.gitignore` following gem development best practices.
|
|
31
|
+
- Update copyright year to 2018-2026 in `LICENSE.txt`.
|
|
32
|
+
- Clean up invisible `\u200E` (Left-to-Right Mark) control characters in Arabic vowel table.
|
|
33
|
+
- Clean up placeholder dotted circle `\u25CC` characters in ISO 233 hamza diacritics.
|
|
34
|
+
|
|
35
|
+
### Removed
|
|
36
|
+
- Legacy `.travis.yml` configuration.
|
|
37
|
+
|
|
38
|
+
## [0.1.7] - 2025-04-03
|
|
39
|
+
|
|
40
|
+
### Changed
|
|
41
|
+
- Update gem dependencies and bump version.
|
|
42
|
+
|
|
43
|
+
## [0.1.6] - 2018-09-13
|
|
44
|
+
|
|
45
|
+
### Added
|
|
46
|
+
- ISO 233 transliteration scheme (`:iso233`).
|
|
47
|
+
- Additional test cases for Arabic phrases.
|
|
48
|
+
|
|
49
|
+
## [0.1.5] - 2018-09-13
|
|
50
|
+
|
|
51
|
+
### Changed
|
|
52
|
+
- Refactor language architecture: separate Urdu transliteration into a dedicated module and file.
|
|
53
|
+
|
|
54
|
+
## [0.1.4] - 2018-09-05
|
|
55
|
+
|
|
56
|
+
### Changed
|
|
57
|
+
- Standardize character output to use ASCII characters.
|
|
58
|
+
|
|
59
|
+
## [0.1.3] - 2018-08-17
|
|
60
|
+
|
|
61
|
+
### Added
|
|
62
|
+
- Additional Urdu characters support.
|
|
63
|
+
- Additional test coverage for Urdu transliteration.
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
- Fix Urdu numerals and character mappings.
|
|
67
|
+
|
|
68
|
+
## [0.1.2] - 2018-08-16
|
|
69
|
+
|
|
70
|
+
### Added
|
|
71
|
+
- Additional Urdu symbols (including 'ئ').
|
|
72
|
+
|
|
73
|
+
## [0.1.1] - 2018-08-16
|
|
74
|
+
|
|
75
|
+
### Added
|
|
76
|
+
- Initial Urdu transliteration support.
|
|
77
|
+
|
|
78
|
+
## [0.1.0] - 2018-04-04
|
|
79
|
+
|
|
80
|
+
### Added
|
|
81
|
+
- Initial release.
|
|
82
|
+
- Core Arabic transliteration to Roman (Latin) script.
|
|
83
|
+
- Support for Arabic numerals, punctuation, consonants, and vowels.
|
data/CODE_OF_CONDUCT.md
CHANGED
|
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
|
|
55
55
|
## Enforcement
|
|
56
56
|
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
-
reported by contacting the project team
|
|
58
|
+
reported by contacting the project team. All
|
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
# Arabic
|
|
2
2
|
|
|
3
|
+
[](https://github.com/rovetz/arabic/actions/workflows/ruby.yml)
|
|
4
|
+
[](https://badge.fury.io/rb/arabic)
|
|
5
|
+
|
|
3
6
|
Romanization of Arabic. It transliterates Arabic text to the Roman (Latin) script.
|
|
4
7
|
|
|
5
8
|
## Installation
|
|
@@ -7,7 +10,7 @@ Romanization of Arabic. It transliterates Arabic text to the Roman (Latin) scrip
|
|
|
7
10
|
Add this line to your application's Gemfile:
|
|
8
11
|
|
|
9
12
|
```ruby
|
|
10
|
-
gem
|
|
13
|
+
gem "arabic"
|
|
11
14
|
```
|
|
12
15
|
|
|
13
16
|
And then execute:
|
|
@@ -22,22 +25,62 @@ Or install it yourself as:
|
|
|
22
25
|
|
|
23
26
|
```ruby
|
|
24
27
|
require "arabic"
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
And then
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
# Default Arabic transliteration
|
|
30
30
|
Arabic.transliterate("العربية")
|
|
31
|
-
|
|
32
|
-
or
|
|
31
|
+
# => "alerbyt"
|
|
33
32
|
|
|
34
|
-
|
|
33
|
+
# Short alias .t
|
|
35
34
|
Arabic.t("العربية")
|
|
35
|
+
# => "alerbyt"
|
|
36
|
+
|
|
37
|
+
# Urdu scheme
|
|
38
|
+
Arabic.t("اردو", :urdu)
|
|
39
|
+
# => "ardv"
|
|
40
|
+
|
|
41
|
+
# ISO 233 scheme
|
|
42
|
+
Arabic.t("اردو", :iso233)
|
|
43
|
+
# => "ʾrdw"
|
|
44
|
+
|
|
45
|
+
# Persian scheme
|
|
46
|
+
Arabic.t("فارسی", :persian)
|
|
47
|
+
# => "farsy"
|
|
48
|
+
|
|
49
|
+
# Numbers and punctuation
|
|
50
|
+
Arabic.t("٠١٢٣٤٥٦٧۸٩")
|
|
51
|
+
# => "0123456789"
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Command Line Interface (CLI)
|
|
55
|
+
|
|
56
|
+
You can also use `arabic` directly from the command line:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# Direct argument
|
|
60
|
+
$ arabic "العربية"
|
|
61
|
+
alerbyt
|
|
62
|
+
|
|
63
|
+
# Piped input (STDIN)
|
|
64
|
+
$ echo "العربية" | arabic
|
|
65
|
+
alerbyt
|
|
66
|
+
|
|
67
|
+
# File input
|
|
68
|
+
$ arabic text.txt
|
|
69
|
+
|
|
70
|
+
# Select transliteration scheme (default, urdu, iso233, persian)
|
|
71
|
+
$ arabic -s urdu "اردو"
|
|
72
|
+
ardv
|
|
73
|
+
|
|
74
|
+
$ arabic -s iso233 "كتاب"
|
|
75
|
+
ktʾb
|
|
76
|
+
|
|
77
|
+
$ arabic -s persian "فارسی"
|
|
78
|
+
farsy
|
|
36
79
|
```
|
|
37
80
|
|
|
38
81
|
## Development
|
|
39
82
|
|
|
40
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake
|
|
83
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run tests and code style checks (RuboCop). You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
41
84
|
|
|
42
85
|
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).
|
|
43
86
|
|
|
@@ -51,4 +94,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
51
94
|
|
|
52
95
|
## Code of Conduct
|
|
53
96
|
|
|
54
|
-
Everyone interacting in the Arabic project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rovetz/arabic/blob/
|
|
97
|
+
Everyone interacting in the Arabic project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rovetz/arabic/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "bundler/gem_tasks"
|
|
2
4
|
require "rake/testtask"
|
|
5
|
+
require "rubocop/rake_task"
|
|
3
6
|
|
|
4
7
|
Rake::TestTask.new(:test) do |t|
|
|
5
8
|
t.libs << "test"
|
|
@@ -7,4 +10,6 @@ Rake::TestTask.new(:test) do |t|
|
|
|
7
10
|
t.test_files = FileList["test/**/*_test.rb"]
|
|
8
11
|
end
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
14
|
+
|
|
15
|
+
task default: %i[test rubocop]
|
data/arabic.gemspec
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
5
|
|
|
4
6
|
require "arabic/version"
|
|
@@ -13,15 +15,27 @@ Gem::Specification.new do |spec|
|
|
|
13
15
|
spec.description = "Converts Arabic text to the Roman (Latin) script"
|
|
14
16
|
spec.homepage = "https://github.com/rovetz/arabic"
|
|
15
17
|
spec.license = "MIT"
|
|
18
|
+
spec.required_ruby_version = ">= 3.3.0"
|
|
19
|
+
|
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/rovetz/arabic"
|
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/rovetz/arabic/blob/main/CHANGELOG.md"
|
|
22
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/rovetz/arabic/issues"
|
|
23
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
16
24
|
|
|
17
|
-
spec.files
|
|
18
|
-
|
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
(File.expand_path(f) == __FILE__) ||
|
|
28
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github Gemfile])
|
|
29
|
+
end
|
|
19
30
|
end
|
|
20
31
|
spec.bindir = "exe"
|
|
21
|
-
spec.executables =
|
|
32
|
+
spec.executables = ["arabic"]
|
|
22
33
|
spec.require_paths = ["lib"]
|
|
23
34
|
|
|
24
|
-
spec.add_development_dependency "
|
|
25
|
-
spec.add_development_dependency "
|
|
26
|
-
spec.add_development_dependency "
|
|
35
|
+
spec.add_development_dependency "irb"
|
|
36
|
+
spec.add_development_dependency "minitest", ">= 5.25"
|
|
37
|
+
spec.add_development_dependency "rake", ">= 13.2"
|
|
38
|
+
spec.add_development_dependency "rdoc"
|
|
39
|
+
spec.add_development_dependency "rubocop", ">= 1.64"
|
|
40
|
+
spec.add_development_dependency "simplecov", ">= 0.22"
|
|
27
41
|
end
|
data/exe/arabic
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "optparse"
|
|
5
|
+
require "arabic"
|
|
6
|
+
|
|
7
|
+
scheme = nil
|
|
8
|
+
|
|
9
|
+
parser = OptionParser.new do |opts|
|
|
10
|
+
opts.banner = "Usage: arabic [options] [text | file...]"
|
|
11
|
+
opts.separator ""
|
|
12
|
+
opts.separator "Transliterate Arabic script to Roman script."
|
|
13
|
+
opts.separator ""
|
|
14
|
+
opts.separator "Examples:"
|
|
15
|
+
opts.separator " arabic 'مرحبا'"
|
|
16
|
+
opts.separator " echo 'مرحبا' | arabic"
|
|
17
|
+
opts.separator " arabic text.txt"
|
|
18
|
+
opts.separator " arabic -s urdu 'اردو'"
|
|
19
|
+
opts.separator " arabic -s iso233 'كتاب'"
|
|
20
|
+
opts.separator " arabic -s persian 'فارسی'"
|
|
21
|
+
opts.separator ""
|
|
22
|
+
opts.separator "Options:"
|
|
23
|
+
|
|
24
|
+
opts.on("-s", "--scheme SCHEME", %w[default urdu iso233 persian],
|
|
25
|
+
"Transliteration scheme (default, urdu, iso233, persian)") do |s|
|
|
26
|
+
scheme = s == "default" ? nil : s.to_sym
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
opts.on("-v", "--version", "Show version") do
|
|
30
|
+
puts "arabic #{Arabic::VERSION}"
|
|
31
|
+
exit
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
opts.on("-h", "--help", "Show this help message") do
|
|
35
|
+
puts opts
|
|
36
|
+
exit
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
parser.parse!
|
|
41
|
+
|
|
42
|
+
transliterate = lambda do |text|
|
|
43
|
+
Arabic.transliterate(text, scheme || :arabic)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
if ARGV.empty?
|
|
47
|
+
if $stdin.tty?
|
|
48
|
+
puts parser
|
|
49
|
+
exit 1
|
|
50
|
+
else
|
|
51
|
+
$stdin.each_line do |line|
|
|
52
|
+
puts transliterate.call(line.chomp)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
else
|
|
56
|
+
ARGV.each do |arg|
|
|
57
|
+
if File.file?(arg)
|
|
58
|
+
File.foreach(arg) do |line|
|
|
59
|
+
puts transliterate.call(line.chomp)
|
|
60
|
+
end
|
|
61
|
+
else
|
|
62
|
+
puts transliterate.call(arg)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/arabic/iso233.rb
CHANGED
|
@@ -1,53 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Arabic
|
|
4
|
+
module Iso233
|
|
5
|
+
CHARACTER_TABLE = {
|
|
6
|
+
# Numbers
|
|
7
|
+
"٠" => "0",
|
|
8
|
+
"١" => "1",
|
|
9
|
+
"٢" => "2",
|
|
10
|
+
"٣" => "3",
|
|
11
|
+
"٤" => "4",
|
|
12
|
+
"٥" => "5",
|
|
13
|
+
"٦" => "6",
|
|
14
|
+
"٧" => "7",
|
|
15
|
+
"۸" => "8",
|
|
16
|
+
"٩" => "9",
|
|
17
|
+
# Punctuation
|
|
18
|
+
"،" => ",",
|
|
19
|
+
"؛" => ";",
|
|
20
|
+
"؟" => "?",
|
|
21
|
+
# Consonants (Letters of the Alphabet)
|
|
22
|
+
"ء" => "ˌ",
|
|
23
|
+
"ٔ" => "ˈ",
|
|
24
|
+
"ٕ" => "",
|
|
25
|
+
"ا" => "ʾ",
|
|
26
|
+
"ب" => "b",
|
|
27
|
+
"ت" => "t",
|
|
28
|
+
"ث" => "ṯ",
|
|
29
|
+
"ج" => "ǧ",
|
|
30
|
+
"ح" => "ḥ",
|
|
31
|
+
"خ" => "ẖ",
|
|
32
|
+
"د" => "d",
|
|
33
|
+
"ذ" => "ḏ",
|
|
34
|
+
"ر" => "r",
|
|
35
|
+
"ز" => "z",
|
|
36
|
+
"س" => "s",
|
|
37
|
+
"ش" => "š",
|
|
38
|
+
"ص" => "ṣ",
|
|
39
|
+
"ض" => "ḍ",
|
|
40
|
+
"ط" => "ṭ",
|
|
41
|
+
"ظ" => "ẓ",
|
|
42
|
+
"ع" => "ʿ",
|
|
43
|
+
"غ" => "ġ",
|
|
44
|
+
"ف" => "f",
|
|
45
|
+
"ق" => "q",
|
|
46
|
+
"ك" => "k",
|
|
47
|
+
"ل" => "l",
|
|
48
|
+
"م" => "m",
|
|
49
|
+
"ن" => "n",
|
|
50
|
+
"ه" => "h",
|
|
51
|
+
"ة" => "ẗ",
|
|
52
|
+
"و" => "w",
|
|
53
|
+
"ي" => "y",
|
|
54
|
+
"ى" => "ỳ"
|
|
55
|
+
}.freeze
|
|
56
|
+
|
|
57
|
+
REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
|
|
58
|
+
end
|
|
53
59
|
end
|
|
60
|
+
|
|
61
|
+
Iso233 = Arabic::Iso233 unless defined?(Iso233)
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Arabic
|
|
4
|
+
module Persian
|
|
5
|
+
CHARACTER_TABLE = {
|
|
6
|
+
# Numbers (Persian / Eastern Arabic-Indic digits)
|
|
7
|
+
"۰" => "0",
|
|
8
|
+
"۱" => "1",
|
|
9
|
+
"۲" => "2",
|
|
10
|
+
"۳" => "3",
|
|
11
|
+
"۴" => "4",
|
|
12
|
+
"۵" => "5",
|
|
13
|
+
"۶" => "6",
|
|
14
|
+
"۷" => "7",
|
|
15
|
+
"۸" => "8",
|
|
16
|
+
"۹" => "9",
|
|
17
|
+
# Punctuation
|
|
18
|
+
"،" => ",",
|
|
19
|
+
"؛" => ";",
|
|
20
|
+
"؟" => "?",
|
|
21
|
+
# Consonants (Persian alphabet - 32 letters)
|
|
22
|
+
"ا" => "a",
|
|
23
|
+
"آ" => "aa",
|
|
24
|
+
"ب" => "b",
|
|
25
|
+
"پ" => "p",
|
|
26
|
+
"ت" => "t",
|
|
27
|
+
"ث" => "s",
|
|
28
|
+
"ج" => "j",
|
|
29
|
+
"چ" => "ch",
|
|
30
|
+
"ح" => "h",
|
|
31
|
+
"خ" => "kh",
|
|
32
|
+
"د" => "d",
|
|
33
|
+
"ذ" => "z",
|
|
34
|
+
"ر" => "r",
|
|
35
|
+
"ز" => "z",
|
|
36
|
+
"ژ" => "zh",
|
|
37
|
+
"س" => "s",
|
|
38
|
+
"ش" => "sh",
|
|
39
|
+
"ص" => "s",
|
|
40
|
+
"ض" => "z",
|
|
41
|
+
"ط" => "t",
|
|
42
|
+
"ظ" => "z",
|
|
43
|
+
"ع" => "‘",
|
|
44
|
+
"غ" => "gh",
|
|
45
|
+
"ف" => "f",
|
|
46
|
+
"ق" => "q",
|
|
47
|
+
"ک" => "k",
|
|
48
|
+
"ك" => "k",
|
|
49
|
+
"گ" => "g",
|
|
50
|
+
"ل" => "l",
|
|
51
|
+
"م" => "m",
|
|
52
|
+
"ن" => "n",
|
|
53
|
+
"و" => "v",
|
|
54
|
+
"ه" => "h",
|
|
55
|
+
"ی" => "y",
|
|
56
|
+
"ي" => "y",
|
|
57
|
+
"ء" => "'",
|
|
58
|
+
"ة" => "t",
|
|
59
|
+
"أ" => "a",
|
|
60
|
+
"إ" => "e",
|
|
61
|
+
"ؤ" => "o",
|
|
62
|
+
"ئ" => "y",
|
|
63
|
+
"ى" => "a"
|
|
64
|
+
}.freeze
|
|
65
|
+
|
|
66
|
+
REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
Persian = Arabic::Persian unless defined?(Persian)
|
data/lib/arabic/urdu.rb
CHANGED
|
@@ -1,68 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Arabic
|
|
4
|
+
module Urdu
|
|
5
|
+
CHARACTER_TABLE = {
|
|
6
|
+
# Numbers
|
|
7
|
+
"۰" => "0",
|
|
8
|
+
"۱" => "1",
|
|
9
|
+
"۲" => "2",
|
|
10
|
+
"۳" => "3",
|
|
11
|
+
"۴" => "4",
|
|
12
|
+
"۵" => "5",
|
|
13
|
+
"۶" => "6",
|
|
14
|
+
"۷" => "7",
|
|
15
|
+
"۸" => "8",
|
|
16
|
+
"۹" => "9",
|
|
17
|
+
# Punctuation
|
|
18
|
+
"،" => ",",
|
|
19
|
+
"؛" => ";",
|
|
20
|
+
"؟" => "?",
|
|
21
|
+
# Consonants (Letters of the Alphabet)
|
|
22
|
+
"ا" => "a",
|
|
23
|
+
"آ" => "aa",
|
|
24
|
+
"ب" => "b",
|
|
25
|
+
"پ" => "p",
|
|
26
|
+
"ت" => "t",
|
|
27
|
+
"ٹ" => "t",
|
|
28
|
+
"ث" => "s",
|
|
29
|
+
"ج" => "j",
|
|
30
|
+
"چ" => "c",
|
|
31
|
+
"ح" => "h",
|
|
32
|
+
"خ" => "kh",
|
|
33
|
+
"د" => "d",
|
|
34
|
+
"ڈ" => "d",
|
|
35
|
+
"ذ" => "z",
|
|
36
|
+
"ر" => "r",
|
|
37
|
+
"ڑ" => "r",
|
|
38
|
+
"ز" => "z",
|
|
39
|
+
"ژ" => "zh",
|
|
40
|
+
"س" => "s",
|
|
41
|
+
"ش" => "sh",
|
|
42
|
+
"ص" => "s",
|
|
43
|
+
"ض" => "z",
|
|
44
|
+
"ط" => "t",
|
|
45
|
+
"ظ" => "z",
|
|
46
|
+
"ع" => "‘",
|
|
47
|
+
"غ" => "gh",
|
|
48
|
+
"ف" => "f",
|
|
49
|
+
"ق" => "q",
|
|
50
|
+
"ک" => "k",
|
|
51
|
+
"گ" => "g",
|
|
52
|
+
"ل" => "l",
|
|
53
|
+
"م" => "m",
|
|
54
|
+
"ن" => "n",
|
|
55
|
+
"ں" => "n",
|
|
56
|
+
"و" => "v",
|
|
57
|
+
"ه" => "h",
|
|
58
|
+
"ﮨ" => "h",
|
|
59
|
+
"ﮩ" => "h",
|
|
60
|
+
"ہ" => "h",
|
|
61
|
+
"ھ" => "h",
|
|
62
|
+
"ء" => "'",
|
|
63
|
+
"ة" => "t",
|
|
64
|
+
"ی" => "i",
|
|
65
|
+
"ى" => "y",
|
|
66
|
+
"ئ" => "y",
|
|
67
|
+
"ے" => "e",
|
|
68
|
+
"ۂ" => "a",
|
|
69
|
+
"ؤ" => "o"
|
|
70
|
+
}.freeze
|
|
71
|
+
|
|
72
|
+
REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
|
|
73
|
+
end
|
|
68
74
|
end
|
|
75
|
+
|
|
76
|
+
Urdu = Arabic::Urdu unless defined?(Urdu)
|
data/lib/arabic/version.rb
CHANGED
data/lib/arabic.rb
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require "arabic/version"
|
|
2
4
|
require "arabic/urdu"
|
|
3
5
|
require "arabic/iso233"
|
|
6
|
+
require "arabic/persian"
|
|
4
7
|
|
|
5
8
|
module Arabic
|
|
6
9
|
CHARACTER_TABLE = {
|
|
@@ -56,19 +59,44 @@ module Arabic
|
|
|
56
59
|
"و" => "w",
|
|
57
60
|
"ى" => "a",
|
|
58
61
|
"ي" => "y",
|
|
59
|
-
"و" => "u",
|
|
60
62
|
# Vowels and Diphthongs
|
|
61
|
-
"
|
|
62
|
-
"ُ"
|
|
63
|
-
"
|
|
64
|
-
}
|
|
63
|
+
"َ" => "a",
|
|
64
|
+
"ُ" => "u",
|
|
65
|
+
"ِ" => "i"
|
|
66
|
+
}.freeze
|
|
67
|
+
|
|
68
|
+
REGEXP = Regexp.union(CHARACTER_TABLE.keys).freeze
|
|
69
|
+
|
|
70
|
+
SCHEMES = {
|
|
71
|
+
arabic: [CHARACTER_TABLE, REGEXP].freeze,
|
|
72
|
+
urdu: [Urdu::CHARACTER_TABLE, Urdu::REGEXP].freeze,
|
|
73
|
+
iso233: [Iso233::CHARACTER_TABLE, Iso233::REGEXP].freeze,
|
|
74
|
+
persian: [Persian::CHARACTER_TABLE, Persian::REGEXP].freeze
|
|
75
|
+
}.freeze
|
|
65
76
|
|
|
66
77
|
class << self
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
# Transliterates Arabic, Urdu, Persian, and related text into Latin script.
|
|
79
|
+
#
|
|
80
|
+
# @param string [String, #to_s] The text to transliterate.
|
|
81
|
+
# @param to [Symbol, String] The transliteration scheme (:arabic, :urdu, :iso233, :persian).
|
|
82
|
+
# @return [String] The transliterated Latin script string.
|
|
83
|
+
# @raise [ArgumentError] If the given transliteration scheme is unknown.
|
|
84
|
+
#
|
|
85
|
+
# @example Default Arabic transliteration
|
|
86
|
+
# Arabic.transliterate("العربية") #=> "alerbyt"
|
|
87
|
+
#
|
|
88
|
+
# @example Urdu transliteration using short alias .t
|
|
89
|
+
# Arabic.t("اردو", :urdu) #=> "ardv"
|
|
90
|
+
def transliterate(string = "", to = :arabic)
|
|
91
|
+
scheme = SCHEMES[to.to_s.downcase.to_sym]
|
|
92
|
+
unless scheme
|
|
93
|
+
available = SCHEMES.keys.map(&:inspect).join(", ")
|
|
94
|
+
raise ArgumentError, "Unknown transliteration scheme: #{to.inspect}. Available schemes: #{available}"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
table, regexp = scheme
|
|
98
|
+
string.to_s.gsub(regexp, table)
|
|
70
99
|
end
|
|
71
|
-
|
|
100
|
+
alias t transliterate
|
|
72
101
|
end
|
|
73
|
-
|
|
74
102
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: arabic
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- rovetz
|
|
@@ -10,73 +10,118 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: irb
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
-
- - "
|
|
16
|
+
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: '
|
|
18
|
+
version: '0'
|
|
19
19
|
type: :development
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
|
-
- - "
|
|
23
|
+
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: '
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: minitest
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '5.25'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '5.25'
|
|
26
40
|
- !ruby/object:Gem::Dependency
|
|
27
41
|
name: rake
|
|
28
42
|
requirement: !ruby/object:Gem::Requirement
|
|
29
43
|
requirements:
|
|
30
|
-
- - "
|
|
44
|
+
- - ">="
|
|
31
45
|
- !ruby/object:Gem::Version
|
|
32
46
|
version: '13.2'
|
|
33
47
|
type: :development
|
|
34
48
|
prerelease: false
|
|
35
49
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
50
|
requirements:
|
|
37
|
-
- - "
|
|
51
|
+
- - ">="
|
|
38
52
|
- !ruby/object:Gem::Version
|
|
39
53
|
version: '13.2'
|
|
40
54
|
- !ruby/object:Gem::Dependency
|
|
41
|
-
name:
|
|
55
|
+
name: rdoc
|
|
42
56
|
requirement: !ruby/object:Gem::Requirement
|
|
43
57
|
requirements:
|
|
44
|
-
- - "
|
|
58
|
+
- - ">="
|
|
45
59
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '
|
|
60
|
+
version: '0'
|
|
47
61
|
type: :development
|
|
48
62
|
prerelease: false
|
|
49
63
|
version_requirements: !ruby/object:Gem::Requirement
|
|
50
64
|
requirements:
|
|
51
|
-
- - "
|
|
65
|
+
- - ">="
|
|
52
66
|
- !ruby/object:Gem::Version
|
|
53
|
-
version: '
|
|
67
|
+
version: '0'
|
|
68
|
+
- !ruby/object:Gem::Dependency
|
|
69
|
+
name: rubocop
|
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '1.64'
|
|
75
|
+
type: :development
|
|
76
|
+
prerelease: false
|
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '1.64'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: simplecov
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0.22'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0.22'
|
|
54
96
|
description: Converts Arabic text to the Roman (Latin) script
|
|
55
97
|
email:
|
|
56
98
|
- zakbox@gmail.com
|
|
57
|
-
executables:
|
|
99
|
+
executables:
|
|
100
|
+
- arabic
|
|
58
101
|
extensions: []
|
|
59
102
|
extra_rdoc_files: []
|
|
60
103
|
files:
|
|
61
|
-
- ".
|
|
62
|
-
-
|
|
104
|
+
- ".rubocop.yml"
|
|
105
|
+
- CHANGELOG.md
|
|
63
106
|
- CODE_OF_CONDUCT.md
|
|
64
|
-
- Gemfile
|
|
65
|
-
- Gemfile.lock
|
|
66
107
|
- LICENSE.txt
|
|
67
108
|
- README.md
|
|
68
109
|
- Rakefile
|
|
69
110
|
- arabic.gemspec
|
|
70
|
-
-
|
|
71
|
-
- bin/setup
|
|
111
|
+
- exe/arabic
|
|
72
112
|
- lib/arabic.rb
|
|
73
113
|
- lib/arabic/iso233.rb
|
|
114
|
+
- lib/arabic/persian.rb
|
|
74
115
|
- lib/arabic/urdu.rb
|
|
75
116
|
- lib/arabic/version.rb
|
|
76
117
|
homepage: https://github.com/rovetz/arabic
|
|
77
118
|
licenses:
|
|
78
119
|
- MIT
|
|
79
|
-
metadata:
|
|
120
|
+
metadata:
|
|
121
|
+
source_code_uri: https://github.com/rovetz/arabic
|
|
122
|
+
changelog_uri: https://github.com/rovetz/arabic/blob/main/CHANGELOG.md
|
|
123
|
+
bug_tracker_uri: https://github.com/rovetz/arabic/issues
|
|
124
|
+
rubygems_mfa_required: 'true'
|
|
80
125
|
rdoc_options: []
|
|
81
126
|
require_paths:
|
|
82
127
|
- lib
|
|
@@ -84,14 +129,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
84
129
|
requirements:
|
|
85
130
|
- - ">="
|
|
86
131
|
- !ruby/object:Gem::Version
|
|
87
|
-
version:
|
|
132
|
+
version: 3.3.0
|
|
88
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
134
|
requirements:
|
|
90
135
|
- - ">="
|
|
91
136
|
- !ruby/object:Gem::Version
|
|
92
137
|
version: '0'
|
|
93
138
|
requirements: []
|
|
94
|
-
rubygems_version:
|
|
139
|
+
rubygems_version: 4.0.20
|
|
95
140
|
specification_version: 4
|
|
96
141
|
summary: Romanization (transliteration) of Arabic
|
|
97
142
|
test_files: []
|
data/.gitignore
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/Gemfile.lock
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
PATH
|
|
2
|
-
remote: .
|
|
3
|
-
specs:
|
|
4
|
-
arabic (0.1.7)
|
|
5
|
-
|
|
6
|
-
GEM
|
|
7
|
-
remote: https://rubygems.org/
|
|
8
|
-
specs:
|
|
9
|
-
minitest (5.25.5)
|
|
10
|
-
rake (13.2.1)
|
|
11
|
-
|
|
12
|
-
PLATFORMS
|
|
13
|
-
ruby
|
|
14
|
-
|
|
15
|
-
DEPENDENCIES
|
|
16
|
-
arabic!
|
|
17
|
-
bundler (~> 2.6)
|
|
18
|
-
minitest (~> 5.25)
|
|
19
|
-
rake (~> 13.2)
|
|
20
|
-
|
|
21
|
-
BUNDLED WITH
|
|
22
|
-
2.6.7
|
data/bin/console
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "arabic"
|
|
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__)
|