SPEC-7531 Change Code/CryEngine to Code/Legacy (#1634)
* git mv Code\CryEngine Code\Legacy * redirecting CMakeLists.txt * fixing uic warning * Some more CryEngine mentions * validation scripts Signed-off-by: Esteban Papp <81431996+amznestebanpapp@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) Contributors to the Open 3D Engine Project
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 OR MIT
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// Returns the string version of any type convertible by AZStd::to_string()
|
||||
// otherwise throws a compile error.
|
||||
template <typename T>
|
||||
AZStd::string LocalizationHelpers::DataToString(T t)
|
||||
{
|
||||
return AZStd::to_string(t);
|
||||
}
|
||||
|
||||
// Need a function to specifically handle AZStd::string, since AZStd::to_string() doesn't handle it.
|
||||
AZStd::string LocalizationHelpers::DataToString(AZStd::string str)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
// Need a function to specifically handle const char*, since AZStd::to_string() doesn't handle it.
|
||||
AZStd::string LocalizationHelpers::DataToString(const char* str)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
|
||||
// Base case of the recursive function to convert a data list to strings
|
||||
template<typename T>
|
||||
void LocalizationHelpers::ConvertValuesToStrings(AZStd::vector<AZStd::string>& values, T t)
|
||||
{
|
||||
values.push_back(DataToString(t));
|
||||
}
|
||||
|
||||
// Recursive function to convert a data list to strings
|
||||
template<typename T, typename... Args>
|
||||
void LocalizationHelpers::ConvertValuesToStrings(AZStd::vector<AZStd::string>& values, T t, Args... args)
|
||||
{
|
||||
values.push_back(DataToString(t));
|
||||
ConvertValuesToStrings(values, args...);
|
||||
}
|
||||
|
||||
// Check if a key string is in a list of substitution strings
|
||||
bool LocalizationHelpers::IsKeyInList(const AZStd::vector<AZStd::string>& keys, const AZStd::string& target, int& index)
|
||||
{
|
||||
for (index = 0; index < keys.size(); ++index)
|
||||
{
|
||||
if (keys[index] == target)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
index = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Summary:
|
||||
// Parse localized string and substitute data in for each key that is surrounded by curly braces. Number of arguments
|
||||
// after 'const AZStd::vector<AZStd::string>& keys' should be equal to the number of strings in 'keys'.
|
||||
// ex:
|
||||
// float distance = GetWinDistance();
|
||||
// AZStd::string winState = IsPlayerFirstPlace() ? "won" : "lost";
|
||||
// LocalizationManagerRequests::Broadcast(&LocalizationManagerRequests::Events::LocalizeAndSubstitute<float, AZStd::string>
|
||||
// , "@QUICKRESULTS_DISTANCEDIFFERENCE, outLocalizedString
|
||||
// , MakeLocKeyString("race_result", "distance_ahead")
|
||||
// , winState, distance);
|
||||
//
|
||||
// where "@QUICKRESULTS_DISTANCEDIFFERENCE" would be localized to "You {race_result} by {distance_ahead} meters!" and then
|
||||
// "{race_result}" would be replaced by 'winState" and "{distance_ahead}" would be replaced by the 'distance' argument as a string.
|
||||
template<typename T, typename... Args>
|
||||
void LocalizationManagerRequests::LocalizeAndSubstitute(const AZStd::string& locString, AZStd::string& outLocalizedString, const AZStd::vector<AZStd::string>& keys, T t, Args... args)
|
||||
{
|
||||
AZStd::vector<AZStd::string> values;
|
||||
LocalizationHelpers::ConvertValuesToStrings(values, t, args...);
|
||||
|
||||
outLocalizedString = locString;
|
||||
LocalizationManagerRequestBus::Broadcast(&LocalizationManagerRequestBus::Events::LocalizeAndSubstituteInternal, outLocalizedString, keys, values);
|
||||
}
|
||||
Reference in New Issue
Block a user