Improve multi (#7136)
[opentx.git] / radio / src / translations / tts_ru.cpp
blob728492741f13294bfb1caa0193be0ae0a43daa4d
1 /*
2 * Author
3 * - Alexander Novikov (mr.pokryshkin@gmail.com)
5 * tts_ru is based on tts_de and tts_en
7 * opentx is based on code named
8 * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
9 * er9x by Erez Raviv: http://code.google.com/p/er9x/,
10 * and the original (and ongoing) project by
11 * Thomas Husterer, th9x: http://code.google.com/p/th9x/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2 as
15 * published by the Free Software Foundation.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
24 #include "opentx.h"
26 enum RusPrompts {
27 RU_PROMPT_NUMBERS_BASE = 0,
28 RU_PROMPT_ZERO = RU_PROMPT_NUMBERS_BASE+0, //02-99
29 RU_PROMPT_HUNDRED = RU_PROMPT_NUMBERS_BASE+100, //100,200 .. 900
31 RU_PROMPT_AND = RU_PROMPT_NUMBERS_BASE+110, // и
32 RU_PROMPT_MINUS = RU_PROMPT_NUMBERS_BASE+111, // минус
33 RU_PROMPT_UNITS_BASE = RU_PROMPT_NUMBERS_BASE + 113,
34 RU_PROMPT_POINT_BASE = RU_PROMPT_NUMBERS_BASE + 165, //.0 - .9
35 RU_PROMPT_FEMALE_ONE = RU_PROMPT_NUMBERS_BASE + 180,
36 RU_PROMPT_FEMALE_TWO = RU_PROMPT_NUMBERS_BASE + 190,
38 RU_PROMPT_THOUSAND1 = RU_PROMPT_NUMBERS_BASE+200, //1000
39 RU_PROMPT_THOUSAND2 = RU_PROMPT_NUMBERS_BASE+201, //2000
40 RU_PROMPT_THOUSAND5 = RU_PROMPT_NUMBERS_BASE+202, //5000
42 #define MALE 0x00
43 #define FEMALE 0x01
44 #define RU_FEMALE_UNIT 0xFF
47 #define RU_PUSH_UNIT_PROMPT(u, p) ru_pushUnitPrompt((u), (p), id)
49 I18N_PLAY_FUNCTION(ru, pushUnitPrompt, uint8_t unitprompt, int16_t number)
51 if (number < 0){ // if negative number, we have to use 2 units form (for example value = 1.3)
52 PUSH_UNIT_PROMPT(unitprompt, 2);
54 else{
55 int16_t mod10 = number % 10;
56 if (number == 0)
57 PUSH_UNIT_PROMPT(unitprompt, 0);
58 else if (number == 1)
59 PUSH_UNIT_PROMPT(unitprompt, 1);
60 else if (number>=2 && number <=4)
61 PUSH_UNIT_PROMPT(unitprompt, 2);
62 else if (number>=5 && number <=20)
63 PUSH_UNIT_PROMPT(unitprompt, 5);
64 else if (mod10 == 1)
65 PUSH_UNIT_PROMPT(unitprompt, 1);
66 else if (mod10 >= 2 && mod10 <=4)
67 PUSH_UNIT_PROMPT(unitprompt, 2);
68 else
69 PUSH_UNIT_PROMPT(unitprompt, 5);
73 I18N_PLAY_FUNCTION(ru, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
75 if (number < 0) {
76 PUSH_NUMBER_PROMPT(RU_PROMPT_MINUS);
77 number = -number;
80 div_t qr = div((int)number, 10);
81 int8_t mode = MODE(att);
82 if (mode > 0 && att != RU_FEMALE_UNIT) {
83 if (mode == 2) {
84 number /= 10;
86 if (qr.rem) {
87 PLAY_NUMBER(qr.quot, 0, 0);
88 PUSH_NUMBER_PROMPT(RU_PROMPT_POINT_BASE + qr.rem);
89 number = -1;
91 else {
92 number = qr.quot;
96 int16_t tmp = number;
98 if (number >= 1000) {
99 PLAY_NUMBER(number / 1000, RU_FEMALE_UNIT, 0); // female
100 uint8_t thousands = number / 1000;
101 int16_t mod10 = thousands % 10;
102 if (thousands == 1)
103 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND1);
104 else if (thousands>=2 && thousands <=4)
105 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND2);
106 else if (thousands>=5 && thousands <=20)
107 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND5);
108 else if (mod10 == 1)
109 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND1);
110 else if (mod10 >= 2 && mod10 <=4)
111 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND2);
112 else
113 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND5);
114 number %= 1000;
115 if (number == 0)
116 number = -1;
118 if (number >= 100) {
119 PUSH_NUMBER_PROMPT(RU_PROMPT_HUNDRED + (number/100)-1);
120 number %= 100;
121 if (number == 0)
122 number = -1;
124 if (number >= 0) {
125 uint8_t attr = MALE;
126 switch(unit) {
127 case RU_FEMALE_UNIT:
128 case UNIT_MPH:
129 case UNIT_FLOZ:
130 case UNIT_MINUTES:
131 case UNIT_SECONDS:
132 attr = FEMALE;
133 break;
134 default:
135 attr = MALE;
136 break;
138 uint8_t lastDigit = number % 10;
139 uint8_t ten=(number - (number % 10))/10;
140 if (lastDigit == 1 && number != 11 && attr == FEMALE)
141 PUSH_NUMBER_PROMPT(RU_PROMPT_FEMALE_ONE + ten);
142 else if (lastDigit == 2 && number !=12 && attr == FEMALE)
143 PUSH_NUMBER_PROMPT(RU_PROMPT_FEMALE_TWO + ten);
144 else
145 PUSH_NUMBER_PROMPT(RU_PROMPT_ZERO + number);
148 if (unit) {
149 if (mode > 0 && qr.rem) // number with decimal point
150 RU_PUSH_UNIT_PROMPT(unit, -1); // force 2 units form, if float value
151 else
152 RU_PUSH_UNIT_PROMPT(unit, tmp);
156 I18N_PLAY_FUNCTION(ru, playDuration, int seconds PLAY_DURATION_ATT)
158 if (seconds == 0) {
159 PLAY_NUMBER(seconds, 0, 0);
160 return;
163 if (seconds < 0) {
164 PUSH_NUMBER_PROMPT(RU_PROMPT_MINUS);
165 seconds = -seconds;
168 uint8_t tmp = seconds / 3600;
169 seconds %= 3600;
170 if (tmp > 0 || IS_PLAY_TIME()) {
171 PLAY_NUMBER(tmp, UNIT_HOURS, 0);
174 tmp = seconds / 60;
175 seconds %= 60;
176 if (tmp > 0) {
177 PLAY_NUMBER(tmp, UNIT_MINUTES, 0);
178 if (seconds > 0)
179 PUSH_NUMBER_PROMPT(RU_PROMPT_AND);
181 if (seconds > 0) {
182 PLAY_NUMBER(seconds, UNIT_SECONDS, 0);
186 LANGUAGE_PACK_DECLARE(ru, "Russian");