Git Product home page Git Product logo

cpp-mylanguage's Introduction

C++ MyLanguage

My Language Cpp TINY Library

A c++ library to handle and manage all of words/strings and languages of a software in a JSON structure.

If your software is a bit international and you want to handle and manage all of strings and languages from server.

JSON is a good format and you can easily seperate words and strings into diffrent parts. But main problem is how to parse a complex JSON structure in c++ and use this.

We need to parse JSON and access to each element and value of JSON at the runtime. In this library I did implenment some useful function to easily parse and use JSON structure and store in a std::map, So you can easily access to strings anywhere.

You can check the input.json file to better understand how the library works.

Purpose of library

Did you translate words to different languages? Do your software support multi language and you want to handle languages without suffering.

So you can try or improve this library for your use.

How To Build

Thanks to CMake, it's simple:

$ mkdir build;
$ cd build;
$ cmake ..; make -j`nproc`

After a successful build, you have:

  1. The static build: output/lib
  2. The shared build: output/lib
  3. The binary build: output/bin
  4. The header files: output/lib/include

Let me know if it's not enough for you.

Example

#include "my_language.hpp"

Language lang;
lang.setFile("input.json");
lang.parse();

lang.log();

std::cout << "------------------------------ [ TEST getString ] -----------------------------\n";

std::cout << lang.getString("exceptions", "fa_IR", "error")->default_value() << "\n";

std::cout << lang.getString("exceptions", "en_US", "error")->default_value() << "\n";



std::cout << "------------------------------ [ TEST getString has_error ] -----------------------------\n";

auto i = lang.getString("exceptions", "en_US", "_bad_keyword_bad_");
std::cout << "...\n";
if(i->has_error()) {
    std::cout << "A error...\n";
}
else {
    std::cout << i->has_error() << "\n";
}


std::cout << "------------------------------ [ TEST hasString ] -----------------------------\n";

bool j = lang.hasString("exceptions", "en_US", "_bad_keyword_bad_");
if(j == true) {
    std::cout << "No error!\n";
}
else {
    std::cout << "A error...\n";
}

j = lang.hasString("exceptions", "en_US", "error");
if(j == true) {
    std::cout << "No error!\n";
}
else {
    std::cout << "A error...\n";
}


std::cout << "------------------------------ [ TEST getString in another sheet ] -----------------------------\n";

auto k = lang.getString("global", "fa_IR", "name");
if(k->has_error()) {
    std::cout << "A error...\n";
}
else {
    std::cout << k->default_value() << std::endl;
}

Acknowledgment

Thank a lots from Mr. Ghasem Ramezani Manesh for his review and improving this library.

I'm not good in c++ so maybe some parts are not well, In any case you can contribute or improve this one and I would accept and will merge this with love )

© Copyright Max Base

cpp-mylanguage's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

jbampton

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.