Almost done with new language tools
This commit is contained in:
@@ -5,8 +5,12 @@
|
||||
|
||||
set(D ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
list(APPEND
|
||||
set(
|
||||
DAWN_TOOL_SOURCES
|
||||
${D}/DawnTool.cpp
|
||||
${D}/File.cpp
|
||||
${D}/Language.cpp
|
||||
|
||||
CACHE INTERNAL
|
||||
${DAWN_CACHE_TARGET}
|
||||
)
|
@@ -20,6 +20,7 @@
|
||||
#define FILE_PATH_SEP '/'
|
||||
#define fileMkdir(path, perms) mkdir(path, perms)
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#define FILE_BUFFER_SIZE 512
|
||||
|
||||
@@ -31,11 +32,11 @@ namespace Dawn {
|
||||
|
||||
class File {
|
||||
private:
|
||||
FILE *file = nullptr;
|
||||
enum FileMode mode;
|
||||
size_t length;
|
||||
|
||||
public:
|
||||
FILE *file = nullptr;
|
||||
static std::string normalizeSlashes(std::string str);
|
||||
static void mkdirp(std::string path);
|
||||
|
||||
|
36
src/dawntools/util/Language.cpp
Normal file
36
src/dawntools/util/Language.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Language.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
int32_t languageSaveStrings(
|
||||
std::string languagesDir,
|
||||
std::vector<struct LanguageString> strings
|
||||
) {
|
||||
if(languagesDir.size() <= 0) {
|
||||
std::cout << "Languages dir is not defined" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
File file(languagesDir);
|
||||
if(!file.mkdirp()) {
|
||||
std::cout << "Failed to create languages string output dir " << file.filename << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Now convert to xml
|
||||
std::string buffer;
|
||||
auto it = strings.begin();
|
||||
while(it != strings.end()) {
|
||||
auto s = *it;
|
||||
buffer += s.lang + "|" + s.key + "|" + s.text + "|";
|
||||
++it;
|
||||
}
|
||||
file.writeString(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
19
src/dawntools/util/Language.hpp
Normal file
19
src/dawntools/util/Language.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/Xml.hpp"
|
||||
#include "util/File.hpp"
|
||||
|
||||
struct LanguageString {
|
||||
std::string key;
|
||||
std::string lang;
|
||||
std::string text;
|
||||
};
|
||||
|
||||
static int32_t languageSaveStrings(
|
||||
std::string languagesDir,
|
||||
std::vector<struct LanguageString> strings
|
||||
);
|
Reference in New Issue
Block a user