| 1 | 28 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 28 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Test::BDD::Cucumber::I18n 0.87; | ||||||||||
| 5 | |||||||||||
| 6 | =encoding utf8 | ||||||||||
| 7 | |||||||||||
| 8 | =head1 NAME | ||||||||||
| 9 | |||||||||||
| 10 | Test::BDD::Cucumber::I18N - Internationalization | ||||||||||
| 11 | |||||||||||
| 12 | =head1 VERSION | ||||||||||
| 13 | |||||||||||
| 14 | version 0.87 | ||||||||||
| 15 | |||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||
| 17 | |||||||||||
| 18 | Internationalization of feature files and step definitions. | ||||||||||
| 19 | |||||||||||
| 20 | =head1 SYNOPSIS | ||||||||||
| 21 | |||||||||||
| 22 | use Test::BDD::Cucumber::I18n | ||||||||||
| 23 | qw(languages has_language langdef); | ||||||||||
| 24 | |||||||||||
| 25 | # get codes of supported languages | ||||||||||
| 26 | my @supported_languages = languages(); | ||||||||||
| 27 | |||||||||||
| 28 | # look up if a language is supported | ||||||||||
| 29 | my $language_is_supported = has_language('de'); | ||||||||||
| 30 | |||||||||||
| 31 | # get definition of a language | ||||||||||
| 32 | my $langdef = langdef('de'); | ||||||||||
| 33 | |||||||||||
| 34 | # get readable keyword definitions | ||||||||||
| 35 | my $string = readable_keywords | ||||||||||
| 36 | |||||||||||
| 37 | =cut | ||||||||||
| 38 | |||||||||||
| 39 | 28 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | |||||||||||
| 41 | 28 | ▶ | use base 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | |||||||||||
| 43 | 28 | our @EXPORT_OK = | |||||||||
| 44 | qw(languages langdef has_language readable_keywords keyword_to_subname); | ||||||||||
| 45 | |||||||||||
| 46 | 28 | ▶ | use Test::BDD::Cucumber::I18N::Data; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 47 | |||||||||||
| 48 | =head1 METHODS | ||||||||||
| 49 | |||||||||||
| 50 | =head2 languages | ||||||||||
| 51 | |||||||||||
| 52 | Get codes of supported languages. | ||||||||||
| 53 | |||||||||||
| 54 | =cut | ||||||||||
| 55 | |||||||||||
| 56 | 23 | ▶ | sub languages { | ||||||||
|
Subroutine
languages: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 57 | 23 | return sort keys %Test::BDD::Cucumber::I18N::Data::languages; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | =head2 has_language($language) | ||||||||||
| 61 | |||||||||||
| 62 | Check if a language is supported. Takes as argument the language | ||||||||||
| 63 | abbreviation defined in C<share/i18n.json>. | ||||||||||
| 64 | |||||||||||
| 65 | =cut | ||||||||||
| 66 | |||||||||||
| 67 | 1755 | ▶ | sub has_language { | ||||||||
|
Subroutine
has_language: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 68 | 1755 | my ($language) = @_; | |||||||||
| 69 | 1755 | return exists $Test::BDD::Cucumber::I18N::Data::languages{$language}; | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | =head2 langdef($language) | ||||||||||
| 73 | |||||||||||
| 74 | Get definition of a language. Takes as argument the language abbreviation | ||||||||||
| 75 | defined in C<share/i18n.json>. | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||
| 78 | |||||||||||
| 79 | 1755 | ▶ | sub langdef { | ||||||||
|
Subroutine
langdef: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 80 | 1755 | my ($language) = @_; | |||||||||
| 81 | |||||||||||
| 82 | 1755 | ▶ | return unless has_language($language); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 1755 | return $Test::BDD::Cucumber::I18N::Data::languages{$language}; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | =head2 readable_keywords($string, $transform) | ||||||||||
| 87 | |||||||||||
| 88 | Get readable keyword definitions. | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | 0 | ▶ | sub readable_keywords { | ||||||||
|
Subroutine
readable_keywords: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 93 | 0 | my ( $string, $transform ) = @_; | |||||||||
| 94 | |||||||||||
| 95 | 0 | my @keywords = split( /\|/, $string ); | |||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | @keywords = map { $transform->($_) } @keywords if $transform; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | |||||||||||
| 99 | 0 | return join( ', ', map { '"' . $_ . '"' } @keywords ); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | =head2 keyword_to_subname | ||||||||||
| 103 | |||||||||||
| 104 | Return a keyword into a subname with non-word characters removed. | ||||||||||
| 105 | |||||||||||
| 106 | =cut | ||||||||||
| 107 | |||||||||||
| 108 | 8646 | ▶ | sub keyword_to_subname { | ||||||||
|
Subroutine
keyword_to_subname: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 109 | 8646 | my ($word) = @_; | |||||||||
| 110 | |||||||||||
| 111 | # remove non-word characters so we have a decent sub name | ||||||||||
| 112 | 8646 | $word =~ s{[^\p{Word}]}{}g; | |||||||||
| 113 | |||||||||||
| 114 | 8646 | return $word; | |||||||||
| 115 | } | ||||||||||
| 116 | |||||||||||
| 117 | =head1 LANGUAGES | ||||||||||
| 118 | |||||||||||
| 119 | Languages are defined in L<Test::BDD::Cucumber::I18N::Data>, and have been | ||||||||||
| 120 | lifted from the Gherkin distribution. | ||||||||||
| 121 | |||||||||||
| 122 | =head1 AUTHOR | ||||||||||
| 123 | |||||||||||
| 124 | Gregor Goldbach C<glauschwuffel@nomaden.org> | ||||||||||
| 125 | (based on the works of Pablo Duboue) | ||||||||||
| 126 | |||||||||||
| 127 | =head1 LICENSE | ||||||||||
| 128 | |||||||||||
| 129 | Copyright 2019-2023, Erik Huelsmann | ||||||||||
| 130 | Copyright 2014-2019, Gregor Goldbach; Licensed under the same terms as Perl | ||||||||||
| 131 | |||||||||||
| 132 | =cut | ||||||||||
| 133 | |||||||||||
| 134 | 28 | 1; | |||||||||