Fix doc path
[opentx.git] / radio / src / translations / tts_ru.cpp
blob0ad2db065e56eec4225638df99d23c5edd2ef76b
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
46 #if defined(VOICE)
48 #if defined(CPUARM)
49 #define RU_PUSH_UNIT_PROMPT(u, p) ru_pushUnitPrompt((u), (p), id)
50 #else
51 #define RU_PUSH_UNIT_PROMPT(u, p) pushUnitPrompt((u), (p))
52 #endif
54 I18N_PLAY_FUNCTION(ru, pushUnitPrompt, uint8_t unitprompt, int16_t number)
56 #if defined(CPUARM)
57 if (number < 0){ // if negative number, we have to use 2 units form (for example value = 1.3)
58 PUSH_UNIT_PROMPT(unitprompt, 2);
60 else{
61 int16_t mod10 = number % 10;
62 if (number == 0)
63 PUSH_UNIT_PROMPT(unitprompt, 0);
64 else if (number == 1)
65 PUSH_UNIT_PROMPT(unitprompt, 1);
66 else if (number>=2 && number <=4)
67 PUSH_UNIT_PROMPT(unitprompt, 2);
68 else if (number>=5 && number <=20)
69 PUSH_UNIT_PROMPT(unitprompt, 5);
70 else if (mod10 == 1)
71 PUSH_UNIT_PROMPT(unitprompt, 1);
72 else if (mod10 >= 2 && mod10 <=4)
73 PUSH_UNIT_PROMPT(unitprompt, 2);
74 else
75 PUSH_UNIT_PROMPT(unitprompt, 5);
77 #else
79 // TODO: add rules for Russian language
80 unitprompt = RU_PROMPT_UNITS_BASE + unitprompt*4;
81 if (number == 1)
82 PUSH_NUMBER_PROMPT(unitprompt);
83 else
84 PUSH_NUMBER_PROMPT(unitprompt+1);
85 #endif
88 I18N_PLAY_FUNCTION(ru, playNumber, getvalue_t number, uint8_t unit, uint8_t att)
90 if (number < 0) {
91 PUSH_NUMBER_PROMPT(RU_PROMPT_MINUS);
92 number = -number;
95 #if !defined(CPUARM)
96 if (unit) {
97 unit--;
98 convertUnit(number, unit);
99 if (IS_IMPERIAL_ENABLE()) {
100 if (unit == UNIT_DIST) {
101 unit = UNIT_FEET;
103 if (unit == UNIT_SPEED) {
104 unit = UNIT_KTS;
107 unit++;
109 #endif
110 div_t qr = div((int)number, 10);
111 int8_t mode = MODE(att);
112 if (mode > 0 && att != RU_FEMALE_UNIT) {
113 #if defined(CPUARM)
114 if (mode == 2) {
115 number /= 10;
117 #else
118 // we assume that we are PREC1
119 #endif
120 if (qr.rem) {
121 PLAY_NUMBER(qr.quot, 0, 0);
122 PUSH_NUMBER_PROMPT(RU_PROMPT_POINT_BASE + qr.rem);
123 number = -1;
125 else {
126 number = qr.quot;
130 int16_t tmp = number;
132 if (number >= 1000) {
133 PLAY_NUMBER(number / 1000, RU_FEMALE_UNIT, 0); // female
134 uint8_t thousands = number / 1000;
135 int16_t mod10 = thousands % 10;
136 if (thousands == 1)
137 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND1);
138 else if (thousands>=2 && thousands <=4)
139 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND2);
140 else if (thousands>=5 && thousands <=20)
141 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND5);
142 else if (mod10 == 1)
143 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND1);
144 else if (mod10 >= 2 && mod10 <=4)
145 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND2);
146 else
147 PUSH_NUMBER_PROMPT(RU_PROMPT_THOUSAND5);
148 number %= 1000;
149 if (number == 0)
150 number = -1;
152 if (number >= 100) {
153 PUSH_NUMBER_PROMPT(RU_PROMPT_HUNDRED + (number/100)-1);
154 number %= 100;
155 if (number == 0)
156 number = -1;
158 if (number >= 0) {
159 uint8_t attr = MALE;
160 switch(unit) {
161 case RU_FEMALE_UNIT:
162 case UNIT_MPH:
163 case UNIT_FLOZ:
164 case UNIT_MINUTES:
165 case UNIT_SECONDS:
166 attr = FEMALE;
167 break;
168 default:
169 attr = MALE;
170 break;
172 uint8_t lastDigit = number % 10;
173 uint8_t ten=(number - (number % 10))/10;
174 if (lastDigit == 1 && number != 11 && attr == FEMALE)
175 PUSH_NUMBER_PROMPT(RU_PROMPT_FEMALE_ONE + ten);
176 else if (lastDigit == 2 && number !=12 && attr == FEMALE)
177 PUSH_NUMBER_PROMPT(RU_PROMPT_FEMALE_TWO + ten);
178 else
179 PUSH_NUMBER_PROMPT(RU_PROMPT_ZERO + number);
182 if (unit) {
183 if (mode > 0 && qr.rem) // number with decimal point
184 RU_PUSH_UNIT_PROMPT(unit, -1); // force 2 units form, if float value
185 else
186 RU_PUSH_UNIT_PROMPT(unit, tmp);
190 I18N_PLAY_FUNCTION(ru, playDuration, int seconds PLAY_DURATION_ATT)
192 if (seconds == 0) {
193 PLAY_NUMBER(seconds, 0, 0);
194 return;
197 if (seconds < 0) {
198 PUSH_NUMBER_PROMPT(RU_PROMPT_MINUS);
199 seconds = -seconds;
202 uint8_t tmp = seconds / 3600;
203 seconds %= 3600;
204 if (tmp > 0 || IS_PLAY_TIME()) {
205 PLAY_NUMBER(tmp, UNIT_HOURS, 0);
208 tmp = seconds / 60;
209 seconds %= 60;
210 if (tmp > 0) {
211 PLAY_NUMBER(tmp, UNIT_MINUTES, 0);
212 if (seconds > 0)
213 PUSH_NUMBER_PROMPT(RU_PROMPT_AND);
215 if (seconds > 0) {
216 PLAY_NUMBER(seconds, UNIT_SECONDS, 0);
220 LANGUAGE_PACK_DECLARE(ru, "Russian");
222 #endif