| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/common/translate/language_detection_util.h" | 5 #include "chrome/common/translate/language_detection_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // for Simplified Chinese. | 145 // for Simplified Chinese. |
| 146 switch (GetCLDMajorVersion()) { | 146 switch (GetCLDMajorVersion()) { |
| 147 #if !defined(CLD_VERSION) || CLD_VERSION==1 | 147 #if !defined(CLD_VERSION) || CLD_VERSION==1 |
| 148 case 1: | 148 case 1: |
| 149 language = | 149 language = |
| 150 LanguageCodeWithDialects(static_cast<Language>(cld_language)); | 150 LanguageCodeWithDialects(static_cast<Language>(cld_language)); |
| 151 break; | 151 break; |
| 152 #endif | 152 #endif |
| 153 #if !defined(CLD_VERSION) || CLD_VERSION==2 | 153 #if !defined(CLD_VERSION) || CLD_VERSION==2 |
| 154 case 2: | 154 case 2: |
| 155 // (1) CLD2's LanguageCode returns general Chinese 'zh' for |
| 156 // CLD2::CHINESE, but Translate server doesn't accept it. This is |
| 157 // converted to 'zh-CN' in the same way as CLD1's |
| 158 // LanguageCodeWithDialects. |
| 159 // |
| 160 // (2) CLD2's LanguageCode returns zh-Hant instead of zh-TW for |
| 161 // CLD2::CHINESE_T. This is technically more precise for the language |
| 162 // code of traditional Chinese, while Translate server hasn't accepted |
| 163 // zh-Hant yet. |
| 155 if (cld_language == CLD2::CHINESE) { | 164 if (cld_language == CLD2::CHINESE) { |
| 156 language = "zh-CN"; | 165 language = "zh-CN"; |
| 166 } else if (cld_language == CLD2::CHINESE_T) { |
| 167 language = "zh-TW"; |
| 157 } else { | 168 } else { |
| 158 language = | 169 language = |
| 159 CLD2::LanguageCode(static_cast<CLD2::Language>(cld_language)); | 170 CLD2::LanguageCode(static_cast<CLD2::Language>(cld_language)); |
| 160 } | 171 } |
| 161 break; | 172 break; |
| 162 #endif | 173 #endif |
| 163 default: | 174 default: |
| 164 NOTREACHED(); | 175 NOTREACHED(); |
| 165 } | 176 } |
| 166 } | 177 } |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 case 2: | 394 case 2: |
| 384 return CLD2::DetectLanguageVersion(); | 395 return CLD2::DetectLanguageVersion(); |
| 385 #endif | 396 #endif |
| 386 default: | 397 default: |
| 387 NOTREACHED(); | 398 NOTREACHED(); |
| 388 } | 399 } |
| 389 return ""; | 400 return ""; |
| 390 } | 401 } |
| 391 | 402 |
| 392 } // namespace LanguageDetectionUtil | 403 } // namespace LanguageDetectionUtil |
| OLD | NEW |