Skip to content

Commit e91af4b

Browse files
committed
Renamed globalization to i18n
Implemented i18n format and spdlog::xxx
1 parent 383525e commit e91af4b

51 files changed

Lines changed: 345 additions & 204 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CppEssenceConfig.cmake.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
include(CMakeFindDependencyMacro)
44

5+
find_dependency(
6+
nlohmann_json
7+
REQUIRED
8+
HINTS @PACKAGE_CMAKE_INSTALL_PREFIX@
9+
NO_DEFAULT_PATH
10+
)
11+
512
find_dependency(
613
spdlog
714
REQUIRED

cmake/ESLangCompiler.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@ function(es_add_lang_resources target_name)
9090
set(ES_USER_NAMESPACE ${ARG_NAMESPACE})
9191

9292
set(base_dir ${output_dir})
93-
set(miu_source_file ${base_dir}/user_globalization_${ES_USER_NAME}.ixx)
94-
set(private_source_file ${base_dir}/user_globalization_${ES_USER_NAME}.cpp)
93+
set(miu_source_file ${base_dir}/user_i18n_${ES_USER_NAME}.ixx)
94+
set(private_source_file ${base_dir}/user_i18n_${ES_USER_NAME}.cpp)
9595

9696
configure_file(
97-
${_es_lang_compiler_absolute_current_dir}/config/user_globalization.ixx.in
97+
${_es_lang_compiler_absolute_current_dir}/config/user_i18n.ixx.in
9898
${miu_source_file}
9999
@ONLY
100100
)
101101

102102
configure_file(
103-
${_es_lang_compiler_absolute_current_dir}/config/user_globalization.cpp.in
103+
${_es_lang_compiler_absolute_current_dir}/config/user_i18n.cpp.in
104104
${private_source_file}
105105
@ONLY
106106
)

cmake/ESPackaging.cmake

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
include_guard()
22
include(${CMAKE_CURRENT_LIST_DIR}/ESUtil.cmake)
33

4+
# CMAKE_CURRENT_LIST_DIR will change within functions (with a dynamic scope).
5+
set(_es_packaging_absolute_current_dir ${CMAKE_CURRENT_LIST_DIR})
6+
47
define_property(
58
TARGET
69
PROPERTY ES_INSTALL_FILES
@@ -267,14 +270,11 @@ function(es_make_install_package)
267270
file(REMOVE \${non_miu_sources})"
268271
)
269272

270-
# Removes the non-miu sources from the target script file.
273+
# Removes the non-miu sources and links from the target script file.
271274
install(
272275
CODE " \
273276
set(script_file \"\${CMAKE_INSTALL_PREFIX}/lib/cmake/${ARG_PACKAGE_NAME}/${package_targets}.cmake\")\n \
274-
message(STATUS \"script_file: \${script_file}\")\n \
275-
file(READ \"\${script_file}\" target_script)\n \
276-
string(REGEX REPLACE [=[\"\\\${_IMPORT_PREFIX}/[^\"]*\\.(cpp|cxx)\"]=] \"\" target_script \"\${target_script}\")\n \
277-
file(WRITE \"\${script_file}\" \"\${target_script}\")"
277+
execute_process(COMMAND python3 \"${_es_packaging_absolute_current_dir}/py/patch_exported_modular_target.py\" \"\${script_file}\")"
278278
)
279279
endif()
280280
endfunction()
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import essence.io;
88
CMRC_DECLARE(@ES_USER_NAMESPACE@);
99

1010
namespace @ES_USER_NAMESPACE@ {
11-
const essence::globalization::abstract::translator& get_bounded_translator() {
12-
static const auto translator = essence::globalization::make_translator(
11+
const essence::i18n::abstract::translator& get_bounded_translator() {
12+
static const auto translator = essence::i18n::make_translator(
1313
essence::io::make_cmrc_fs_operator(cmrc::@ES_USER_NAMESPACE@::get_filesystem()));
1414

1515
return translator;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ module;
66

77
export module @ES_USER_NAME@;
88
import essence.basic;
9-
import essence.globalization;
9+
import essence.i18n;
1010
import std;
1111

1212
export namespace @ES_USER_NAMESPACE@ {
1313
#if @ES_WITH_EXPORTS@
14-
ES_API(@ES_USER_NAME@) const essence::globalization::abstract::translator& get_bounded_translator();
14+
ES_API(@ES_USER_NAME@) const essence::i18n::abstract::translator& get_bounded_translator();
1515
#else
16-
const essence::globalization::abstract::translator& get_bounded_translator();
16+
const essence::i18n::abstract::translator& get_bounded_translator();
1717
#endif
1818

1919
inline const std::locale& get_bounded_locale() {
20-
class messages_by_translator : public essence::globalization::simple_messages {
20+
class messages_by_translator : public essence::i18n::simple_messages {
2121
public:
22-
explicit messages_by_translator(essence::globalization::abstract::translator translator)
22+
explicit messages_by_translator(essence::i18n::abstract::translator translator)
2323
: translator_{std::move(translator)} {}
2424

2525
private:
2626
[[nodiscard]] essence::abi::string do_get(std::string_view name) const override {
2727
return translator_.get_text(name);
2828
}
2929

30-
essence::globalization::abstract::translator translator_;
30+
essence::i18n::abstract::translator translator_;
3131
};
3232

3333
static const std::locale locale{std::locale{}, new messages_by_translator{get_bounded_translator()}};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright (c) 2024 The RefValue Project
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
# THE SOFTWARE.
20+
21+
import re
22+
import sys
23+
24+
def patch_exported_modular_target(script_file: str):
25+
index = None
26+
prefix = None
27+
28+
with open(script_file, 'r') as file:
29+
lines = file.readlines()
30+
31+
for i, line in enumerate(lines):
32+
if match := re.match(r'^(.*IMPORTED_CXX_MODULES_LINK_LIBRARIES).*$', line):
33+
index = i
34+
prefix = match.group(1)
35+
continue
36+
37+
if re.match(r'^.*FILES.*$', line):
38+
lines[i] = re.sub(r'"\$\{_IMPORT_PREFIX}/[^\"]*\.(cpp|cxx)"', '', lines[i])
39+
print('Patched: ', lines[i])
40+
continue
41+
42+
match = re.match(r'^.*INTERFACE_LINK_LIBRARIES(.*[\r\n]*)', line)
43+
44+
if match and index is not None:
45+
lines[index] = prefix + match.group(1)
46+
print('Patched: ', lines[index])
47+
index = None
48+
49+
with open(script_file, 'w') as file:
50+
file.writelines(lines)
51+
52+
if __name__ == "__main__":
53+
patch_exported_modular_target(sys.argv[1])

gcovr.cfg

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
exclude = feature-testing/
2-
exclude = include/essence/json.hpp
32
exclude = out/
43
exclude = third-party/
54
exclude = tool/

src/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ set_property(
218218
${CMAKE_SOURCE_DIR}/cmake/RV1109Toolchain.cmake
219219
${CMAKE_SOURCE_DIR}/cmake/RV3588Toolchain.cmake
220220
|
221-
${CMAKE_SOURCE_DIR}/cmake/config/user_globalization.cpp.in
222-
${CMAKE_SOURCE_DIR}/cmake/config/user_globalization.ixx.in
223-
DESTINATIONS cmake cmake/config
221+
${CMAKE_SOURCE_DIR}/cmake/config/user_i18n.cpp.in
222+
${CMAKE_SOURCE_DIR}/cmake/config/user_i18n.ixx.in
223+
|
224+
${CMAKE_SOURCE_DIR}/cmake/py/patch_exported_modular_target.py
225+
DESTINATIONS cmake cmake/config cmake/py
224226
)

src/crypto/asymmetric_key.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ namespace essence::crypto {
156156
public:
157157
explicit impl(void* blob)
158158
: blob_{blob ? static_cast<EVP_PKEY*>(blob)
159-
: throw source_code_aware_runtime_error{U8("The blob must be non-null.")}} {}
159+
: throw formatted_runtime_error{U8("The blob must be non-null.")}} {}
160160

161161
[[nodiscard]] EVP_PKEY* blob() const noexcept {
162162
return blob_.get();

src/crypto/chunk_processor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ namespace essence::crypto {
4343
public:
4444
explicit chain_processor(std::span<abstract::chunk_processor> processors)
4545
: buffer_pair_{processors.size() < 2
46-
? throw source_code_aware_runtime_error{U8(
46+
? throw formatted_runtime_error{U8(
4747
"At least two processors are required to be chained together.")}
4848
: calculate_max_buffer_size(processors)},
4949
finalization_buffer_{make_unique_array<std::byte>(buffer_pair_.buffer->size())},
5050
swapper_{buffer_pair_.in, buffer_pair_.out} {
5151
if (std::ranges::adjacent_find(
5252
processors, std::not_equal_to{}, [](const auto& inner) { return inner.transformer(); })
5353
!= processors.end()) {
54-
throw source_code_aware_runtime_error{
54+
throw formatted_runtime_error{
5555
U8("All processors must be either transformers or inverse transformers at the same time.")};
5656
}
5757

0 commit comments

Comments
 (0)