----------------------------------------------------------------------------
| 380 | |
| 381 | //---------------------------------------------------------------------------- |
| 382 | ctkPluginLocalization ctkPlugin::getPluginLocalization( |
| 383 | const QLocale& locale, const QString& base) const |
| 384 | { |
| 385 | Q_D(const ctkPlugin); |
| 386 | |
| 387 | // There are five searching candidates possible: |
| 388 | // base + |
| 389 | // "_" + language1 + "_" + country1 + ".qm" |
| 390 | // or "_" + language1 + ".qm" |
| 391 | // or "_" + language2 + "_" + country2 + ".qm" |
| 392 | // or "_" + language2 + ".qm" |
| 393 | // or "" + ".qm" |
| 394 | // |
| 395 | // Where language1[_country1[_variation1]] is the requested locale, |
| 396 | // and language2[_country2[_variation2]] is the default locale. |
| 397 | |
| 398 | QChar localeSep('_'); |
| 399 | QChar baseSep('_'); |
| 400 | |
| 401 | QStringList searchCandidates; |
| 402 | |
| 403 | QStringList localeParts = locale.name().split(localeSep); |
| 404 | QStringList defaultParts = QLocale().name().split(localeSep); |
| 405 | |
| 406 | searchCandidates << baseSep + localeParts[0] + localeSep + localeParts[1]; |
| 407 | searchCandidates << baseSep + localeParts[0]; |
| 408 | searchCandidates << baseSep + defaultParts[0] + localeSep + defaultParts[1]; |
| 409 | searchCandidates << baseSep + defaultParts[0]; |
| 410 | searchCandidates << ""; |
| 411 | |
| 412 | QString localizationPath = base.left(base.lastIndexOf('/')); |
| 413 | QStringList resourceList = this->getResourceList(localizationPath); |
| 414 | |
| 415 | foreach(QString resource, resourceList) |
| 416 | { |
| 417 | foreach(QString candidate, searchCandidates) |
| 418 | { |
| 419 | if (resource.endsWith(candidate + ".qm")) |
| 420 | { |
| 421 | return ctkPluginLocalization(localizationPath + '/' + resource, locale, d->q_ptr); |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | return ctkPluginLocalization(); |
| 427 | } |
| 428 | |
| 429 | //---------------------------------------------------------------------------- |
| 430 | ctkVersion ctkPlugin::getVersion() const |
no test coverage detected