56ea12e768d909489938827807f7231ad03c4d80
[kivitendo-erp.git] / SL / Helper / UNECERecommendation20.pm
1 package SL::Helper::UNECERecommendation20;
2
3 use strict;
4 use warnings;
5 use utf8;
6
7 use Exporter qw(import);
8 our @EXPORT_OK = qw(map_name_to_alpha_2_code);
9
10 use List::Util qw(first);
11
12 my @mappings = (
13   # space and time
14   # areas
15   [ 'MTK', qr{^(?:m²|qm|quadrat *meter|quadrat *metre)$}i ],
16
17   # distances
18   [ 'CMT', qr{^(?:cm|centi *meter|centi *metre)$}i ],
19   [ 'MTR', qr{^(?:m|meter|metre)$}i ],
20   [ 'KMT', qr{^(?:km|kilo *meter|kilo *metre)$}i ],
21
22   # durations
23   [ 'SEC', qr{^(?:s|sec|second|sek|sekunde)$}i ],
24   [ 'MIN', qr{^min(?:ute)?$}i ],
25   [ 'HUR', qr{^(?:h(?:our)?|std(?:unde)?)$}i ],
26   [ 'DAY', qr{^(?:day|tag)$}i ],
27   [ 'MON', qr{^mon(?:th|at|atlich)?$}i ],
28   [ 'QAN', qr{^quart(?:er|al|alsweise)?$}i ],
29   [ 'ANN', qr{^(?:yearly|annually|jährlich|Jahr)?$}i ],
30
31   # mass
32   [ 'MGM', qr{^(?:mg|milli *gramm?)$}i ],
33   [ 'GRM', qr{^(?:g|gramm?)$}i ],
34   [ 'KGM', qr{^(?:kg|kilo *gramm?)$}i ],
35   [ 'KTN', qr{^(?:t|tonne|kilo *tonne)$}i ],
36
37   # volumes
38   [ 'MLT', qr{^(?:ml|milli *liter|milli *litre)$}i ],
39   [ 'LTR', qr{^(?:l|liter|litre)$}i ],
40
41   # miscellaneous
42   [ 'C62', qr{^(?:stck|stück|pieces?|pc|psch|pauschal)$}i ],
43 );
44
45 sub map_name_to_code {
46   my ($unit) = @_;
47
48   return undef if ($unit // '') eq '';
49
50   my $code = first { $unit =~ $_->[1] } @mappings;
51   return $code->[0] if $code;
52
53   no warnings 'once';
54   $::lxdebug->message(LXDebug::WARN(), "UNECERecommendation20::map_name_code: no mapping found for '$unit'");
55
56   return undef;
57 }
58
59 1;