Skip to content

Commit 68a3c04

Browse files
Merge pull request #6 from Sinan-Karakaya/feat/cmake
Project structure tweaks
2 parents 45698c0 + 1c2c457 commit 68a3c04

8 files changed

+26
-27
lines changed

CMakeLists.txt

+10
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@ project(cpp-i18n LANGUAGES CXX)
55
set(CMAKE_CXX_STANDARD 20)
66
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fdiagnostics-color=always")
77

8+
# Build library
89
add_subdirectory(src)
910

11+
# Fetch dependencies
12+
include(FetchContent)
13+
14+
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
15+
FetchContent_MakeAvailable(json)
16+
17+
target_link_libraries(cpp-i18n PRIVATE nlohmann_json::nlohmann_json)
18+
19+
# Build tests
1020
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
1121
if (BUILD_TESTING)
1222
add_subdirectory(tests)

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ FetchContent_MakeAvailable(cpp-i18n)
3434
3535
target_link_libraries(
3636
${PROJECT_NAME}
37-
PRIVATE
37+
PRIVATE
3838
cpp-i18n
3939
)
4040
```
@@ -51,12 +51,12 @@ assets/locales/en/basic.json
5151
```
5252

5353
```cpp
54-
#include <Translator.hpp>
54+
#include <cpp-i18n/Translator.hpp>
5555

5656
int main()
5757
{
5858
i18n::Translator t;
59-
59+
6060
std::cout << t.translate("hello", "basic") << std::endl; // "Hello, world!"
6161
// or
6262
std::cout << t("hello", "basic") << std::endl; // "Hello, world!"
@@ -81,14 +81,14 @@ assets/locales/fr/basic.json
8181
```
8282

8383
```cpp
84-
#include <Translator.hpp>
84+
#include <cpp-i18n/Translator.hpp>
8585

8686
int main()
8787
{
8888
i18n::LocaleConfig config;
8989
config.supportedLocales = {"en", "fr"};
9090
i18n::Translator t(config);
91-
91+
9292
std::cout << t("hello", "basic") << std::endl; // "Hello, world!"
9393
t.setLocale("fr");
9494
std::cout << t("hello", "basic") << std::endl; // "Bonjour, monde!"
@@ -113,12 +113,12 @@ assets/locales/en/other.json
113113
```
114114

115115
```cpp
116-
#include <Translator.hpp>
116+
#include <cpp-i18n/Translator.hpp>
117117

118118
int main()
119119
{
120120
i18n::Translator t;
121-
121+
122122
std::cout << t("hello", "basic") << std::endl; // "Hello, world!"
123123
std::cout << t("goodbye", "other") << std::endl; // "Goodbye, world!"
124124
return 0;
@@ -135,14 +135,14 @@ path/to/locales/en/basic.json
135135
```
136136

137137
```cpp
138-
#include <Translator.hpp>
138+
#include <cpp-i18n/Translator.hpp>
139139

140140
int main()
141141
{
142142
i18n::LocaleConfig config;
143143
config.localesDir = "path/to/locales";
144144
i18n::Translator t(config);
145-
145+
146146
std::cout << t("hello", "basic") << std::endl; // "Hello, world!"
147147
return 0;
148148
}
@@ -158,12 +158,12 @@ assets/locales/en/parameters.json
158158
```
159159

160160
```cpp
161-
#include <Translator.hpp>
161+
#include <cpp-i18n/Translator.hpp>
162162

163163
int main()
164164
{
165165
i18n::Translator t;
166-
166+
167167
std::cout << t("hello", "parameters", {{ "name", "John" }}) << std::endl; // "Hello, my name is John!"
168168
return 0;
169169
}
File renamed without changes.

src/CMakeLists.txt

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
cmake_minimum_required(VERSION 3.22.1)
22

33
add_library(cpp-i18n Translator.cpp)
4-
target_include_directories(cpp-i18n PUBLIC ${CMAKE_SOURCE_DIR}/include)
5-
6-
include(FetchContent)
7-
8-
FetchContent_Declare(json URL https://github.com/nlohmann/json/releases/download/v3.11.2/json.tar.xz)
9-
FetchContent_MakeAvailable(json)
10-
11-
target_link_libraries(cpp-i18n PRIVATE nlohmann_json::nlohmann_json)
4+
target_include_directories(cpp-i18n PRIVATE ${CMAKE_SOURCE_DIR}/include)

src/Translator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
** App
66
*/
77

8-
#include "Translator.hpp"
8+
#include <cpp-i18n/Translator.hpp>
99

1010
namespace i18n
1111
{

tests/CMakeLists.txt

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
cmake_minimum_required(VERSION 3.22.1)
22

3-
set(CMAKE_CXX_STANDARD 20)
4-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fdiagnostics-color=always")
5-
6-
include(FetchContent)
73
FetchContent_Declare(
84
Catch2
95
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
106
GIT_TAG v3.0.1
117
)
128
FetchContent_MakeAvailable(Catch2)
139

14-
add_executable(tests src/basic.cpp src/parameters.cpp)
10+
add_executable(tests basic.cpp parameters.cpp)
1511
target_link_libraries(tests PRIVATE nlohmann_json::nlohmann_json)
1612
target_link_libraries(tests PRIVATE Catch2::Catch2)
1713
target_link_libraries(tests PRIVATE cpp-i18n)

tests/src/basic.cpp tests/basic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define CATCH_CONFIG_MAIN
99
#include <catch2/catch.hpp>
1010

11-
#include "Translator.hpp"
11+
#include <cpp-i18n/Translator.hpp>
1212

1313
TEST_CASE("basic", "[basic]")
1414
{

tests/src/parameters.cpp tests/parameters.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//#define CATCH_CONFIG_MAIN
99
#include <catch2/catch.hpp>
1010

11-
#include "Translator.hpp"
11+
#include <cpp-i18n/Translator.hpp>
1212

1313
TEST_CASE("Simple parameter", "[parameters]")
1414
{

0 commit comments

Comments
 (0)