Skip to content

Commit

Permalink
AURORA: Add LanguageManager::getLanguages()
Browse files Browse the repository at this point in the history
Returning a std::vector of all declared supported languages.
  • Loading branch information
DrMcCoy committed Jul 29, 2018
1 parent da3e501 commit dfe6d64
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/aurora/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ void LanguageManager::overrideEncoding(uint32 id, Common::Encoding encoding,
addLanguage(language, id, encoding, encodingLocString);
}

std::vector<Language> LanguageManager::getLanguages() const {
std::vector<Language> languages;

for (LanguageByLanguage::const_iterator l = _langByLang.begin(); l != _langByLang.end(); ++l)
languages.push_back(l->first);

return languages;
}

const LanguageManager::Declaration *LanguageManager::find(Language language) const {
LanguageByLanguage::const_iterator l = _langByLang.find(language);
if (l != _langByLang.end())
Expand Down
4 changes: 4 additions & 0 deletions src/aurora/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define AURORA_LANGUAGE_H

#include <map>
#include <vector>

#include "src/common/types.h"
#include "src/common/singleton.h"
Expand Down Expand Up @@ -158,6 +159,9 @@ class LanguageManager : public Common::Singleton<LanguageManager> {
*/
void overrideEncoding(uint32 id, Common::Encoding encoding, Common::Encoding encodingLocString);

/** Return all declared supported languages for the current game. */
std::vector<Language> getLanguages() const;

/** Construct the internal language ID for an ungendered use of a language.
*
* This is used by Aurora games in contexts where the gender of a player
Expand Down
17 changes: 17 additions & 0 deletions tests/aurora/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
* Unit tests for our LanguageManager.
*/

#include <vector>
#include <algorithm>

#include "gtest/gtest.h"

#include "src/common/util.h"
Expand Down Expand Up @@ -102,6 +105,20 @@ GTEST_TEST_F(LanguageManager, clear) {
"At index " << i;
}

GTEST_TEST_F(LanguageManager, getLanguages) {
LangMan.addLanguage(kLanguageDeclarations[0].language, kLanguageDeclarations[0].id,
kLanguageDeclarations[0].encoding);
LangMan.addLanguage(kLanguageDeclarations[1].language, kLanguageDeclarations[1].id,
kLanguageDeclarations[1].encoding);

const std::vector<Aurora::Language> langs = LangMan.getLanguages();

EXPECT_EQ(langs.size(), 2);

EXPECT_NE(std::find(langs.begin(), langs.end(), kLanguageDeclarations[0].language), langs.end());
EXPECT_NE(std::find(langs.begin(), langs.end(), kLanguageDeclarations[1].language), langs.end());
}

GTEST_TEST_F(LanguageManager, getLanguageIDUngendered) {
LangMan.addLanguages(kLanguageDeclarations, ARRAYSIZE(kLanguageDeclarations));

Expand Down

0 comments on commit dfe6d64

Please sign in to comment.