@@ -39,7 +39,6 @@ pyEchoNext documentation
3939 pyechonext.apidoc_ui
4040 pyechonext.auth
4141 pyechonext.docsgen
42- pyechonext.i18n_l10n
4342 pyechonext.logging
4443 pyechonext.template_engine
4544 pyechonext.utils
@@ -71,10 +70,18 @@ pyEchoNext documentation
7170
7271 </p >
7372
74- EchoNext is a lightweight, fast and scalable web framework for Python
73+ .. raw :: html
74+
75+ <p align =" center" >
76+
77+ .. raw :: html
78+
79+ </p >
7580
7681..
7782
83+ EchoNext is a lightweight, fast and scalable web framework for Python
84+
7885 [!CAUTION] At the moment, EchoNext is under active development, many
7986 things may not work, and this version is not recommended for use (all
8087 at your own risk)
@@ -101,7 +108,7 @@ your agile companion in the world of web development!
101108web applications with lightning speed and flexibility. With EchoNext,
102109you’re not just coding; you’re building a masterpiece!
103110
104- Last stable version: 0.7.14 alpha
111+ Last stable version: 0.7.15 alpha
105112
106113..
107114
@@ -196,7 +203,8 @@ Check Other My Projects
196203⚙️ Functionality
197204----------------
198205
199- - i18n/l10n localization
206+ - i18n/l10n localization with
207+ `hermes-langlib <https://github.com/alexeev-prog/hermes_langlib >`__.
200208- basic project documentation generator
201209- request/response
202210- middlewares (with basic session cookie middleware)
@@ -293,6 +301,113 @@ Example code:
293301
294302You can view examples at `examples directory <./examples >`__.
295303
304+ i18n with hermes-langlib
305+ ~~~~~~~~~~~~~~~~~~~~~~~~
306+
307+ Hermes LangLib - a fast and light python library for translating,
308+ localizing and internationalizing your applications. The library is
309+ aimed at high speed and stability; it can be used in highly loaded
310+ projects.
311+
312+ Directory tree:
313+
314+ ::
315+
316+ ├── example.toml
317+ └── locales
318+ └── default.json
319+
320+ Example config-file ``example.toml ``:
321+
322+ .. code :: toml
323+
324+ locale_directory="locales"
325+ default_locale_file="default.json"
326+ default_language="RU_RU"
327+ translator="google"
328+
329+ Example locale file ``locales/default.json ``:
330+
331+ .. code :: json
332+
333+ {
334+ "locales" : {
335+ "RU" : [" RU_RU" ],
336+ "EN" : [" EN_EN" , " EN_US" ]
337+ },
338+ "RU" : {
339+ "RU_RU" : {
340+ "title" : " Библиотека для интернационализации" ,
341+ "description" : " Библиотека, которая позволит переводить ваши приложения" ,
342+ "mails_message" : {
343+ "plural" : " count" ,
344+ "^0$" : " У вас нет ни одного письма" ,
345+ "11" : " У вас есть {count} писем" ,
346+ "1$|1$" : " У вас есть {count} письмо" ,
347+ "^(2|3|4)$|(2|3|4)$" : " У вас есть {count} письма" ,
348+ "other" : " У вас есть {count} писем"
349+ }
350+ }
351+ },
352+ "EN" : {
353+ "EN_EN" : {
354+ "title" : " Library for internationalization" ,
355+ "description" : " A library that will allow you to translate your applications" ,
356+ "mails_message" : {
357+ "plural" : " count" ,
358+ "^0$" : " You do not have any mail." ,
359+ "^1$" : " You have a new mail." ,
360+ "other" : " You have {count} new mails."
361+ }
362+ },
363+ "EN_US" : {
364+ "title" : " Library for internationalization" ,
365+ "description" : " A library that will allow you to translate your applications" ,
366+ "mails_message" : {
367+ "plural" : " count" ,
368+ "^0$" : " You do not have any mail." ,
369+ "^1$" : " You have a new mail." ,
370+ "other" : " You have {count} new mails."
371+ }
372+ }
373+ }
374+ }
375+
376+ Example usage:
377+
378+ .. code :: python
379+
380+ from hermes_langlib.locales import LocaleManager
381+ from hermes_langlib.storage import load_config
382+
383+ config = load_config(' example.toml' )
384+
385+ locale_manager = LocaleManager(config)
386+ print (locale_manager.get(' title - {version} ' , ' default' , ' RU_RU' , version = " 0.1.0" ))
387+ print (locale_manager.get(' title - {version} ' , ' default' , ' RU' , version = " 0.1.0" ))
388+ print (locale_manager.get(' mails_message.' , ' default' , ' RU_RU' , count = 0 ))
389+ print (locale_manager.get(' mails_message' , ' default' , ' RU_RU' , count = 1 ))
390+ print (locale_manager.get(' mails_message' , ' default' , ' RU_RU' , count = 11 ))
391+ print (locale_manager.get(' mails_message' , ' default' , ' RU_RU' , count = 2 ))
392+ print (locale_manager.get(' mails_message' , ' default' , ' RU_RU' , count = 22 ))
393+ print (locale_manager.get(' mails_message' , ' default' , ' RU_RU' , count = 46 ))
394+ print (locale_manager.get(' mails_message' , ' default' , ' RU_RU' , count = 100000001 ))
395+ print (locale_manager.translate(" You have only three mails" , " en" , ' ru' ))
396+ print (locale_manager.translate(" У вас всего три письма" , " ru" , ' en' ))
397+
398+ You can read `Hermes-Langlib Specification at this
399+ link <https://github.com/alexeev-prog/hermes_langlib/tree/main?tab=readme-ov-file#-specifications> `__.
400+
401+ .. raw :: html
402+
403+ <p align =" right" >
404+
405+
406+
407+ .. raw :: html
408+
409+ </p >
410+
296411Basic With Depends Injection
297412~~~~~~~~~~~~~~~~~~~~~~~~~~~~
298413
@@ -448,142 +563,6 @@ Permissions
448563 if __name__ == " __main__" :
449564 main()
450565
451- FullApp with locale, static files, docs generation
452- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
453-
454- Also see in `examples <./examples/example_locale.py >`__
455-
456- .. code :: python
457-
458- from pyechonext.apidoc_ui import APIDocUI, APIDocumentation
459- from pyechonext.app import ApplicationType, EchoNext
460- from pyechonext.config import SettingsConfigType, SettingsLoader
461- from pyechonext.middleware import middlewares
462- from pyechonext.mvc.controllers import PageController
463- from pyechonext.static import StaticFile
464- from pyechonext.template_engine.jinja import render_template
465- from pyechonext.urls import URL
466- from pyechonext.utils.exceptions import MethodNotAllow
467-
468-
469- class UsersView (PageController ):
470- def get (self , request , response , * args , ** kwargs ):
471- return render_template(
472- request,
473- " index.html" ,
474- user_name = " User" ,
475- session_id = request.session_id,
476- friends = [" Bob" , " Anna" , " John" ],
477- )
478-
479- def post (self , request , response , * args , ** kwargs ):
480- raise MethodNotAllow(f " Request { request.path} : method not allow " )
481-
482-
483- url_patterns = [URL(path = " /users" , controller = UsersView)]
484- config_loader = SettingsLoader(SettingsConfigType.PYMODULE , " el_config.py" )
485- settings = config_loader.get_settings()
486- static_files = [StaticFile(settings, " styles.css" )]
487- echonext = EchoNext(
488- __name__ ,
489- settings,
490- middlewares,
491- urls = url_patterns,
492- application_type = ApplicationType.HTML ,
493- static_files = static_files,
494- )
495- apidoc = APIDocumentation(echonext)
496-
497-
498- @echonext.route_page (" /api-docs" )
499- def api_docs (request , response ):
500- ui = APIDocUI(apidoc.generate_spec())
501- return ui.generate_html_page()
502-
503-
504- @echonext.route_page (" /book" )
505- class BooksResource (PageController ):
506- """
507- This class describes a books resource.
508- """
509-
510- def get (self , request , response , ** kwargs ):
511- """
512- get queries
513-
514- :param request: The request
515- :type request: Request
516- :param response: The response
517- :type response: Response
518- :param kwargs: The keywords arguments
519- :type kwargs: dictionary
520-
521- :returns: result
522- :rtype: str
523- """
524- return echonext.i18n_loader.get_string(" title %{name} " , name = str (request.GET ))
525-
526- def post (self , request , response , ** kwargs ):
527- """
528- post queries
529-
530- :param request: The request
531- :type request: Request
532- :param response: The response
533- :type response: Response
534- :param kwargs: The keywords arguments
535- :type kwargs: dictionary
536-
537- :returns: result
538- :rtype: str
539- """
540- return echonext.l10n_loader.format_currency(1305.50 )
541-
542- Create file ``static/styles.css ``:
543-
544- .. code :: css
545-
546- body {
547- color : #f8f2f2 ;
548- background : #1f1f1f ;
549- font-family : monospace ;
550- }
551-
552- Create file ``el_config.py ``:
553-
554- .. code :: python
555-
556- import os
557-
558- BASE_DIR = os.path.dirname(os.path.abspath(__file__ ))
559- TEMPLATES_DIR = ' templates'
560- SECRET_KEY = ' secret-key'
561- LOCALE = ' RU_RU'
562- LOCALE_DIR = ' locales'
563- VERSION = " 0.1.0"
564- DESCRIPTION = ' Example echonext webapp'
565- STATIC_DIR = ' static'
566-
567- Create file ``locales/RU_RU.json ``:
568-
569- .. code :: python
570-
571- {
572- " i18n" : {
573- " title" : " pyEchoNext Веб-приложение с локалью" ,
574- " example one" : " пример один"
575- },
576- " l10n" : {
577- " date_format" : " %Y-%m-%d " ,
578- " time_format" : " %H:%M" ,
579- " date_time_fromat" : " %Y-%m-%d %H:%M" ,
580- " thousands_separator" : " ," ,
581- " decimal_separator" : " ." ,
582- " currency_symbol" : " $" ,
583- " currency_format" : " {symbol}{amount} "
584- }
585- }
586-
587566 .. raw :: html
588567
589568 <p align =" right" >
@@ -829,12 +808,6 @@ Tests coverage
829808To test the web framework, PyTest with the pytest-cov plugin is used.
830809You can look at the tests in `tests directory <./tests >`__
831810
832- ========== ==== ========
833- Statements Miss Coverage
834- ========== ==== ========
835- 1553 720 54%
836- ========== ==== ========
837-
838811Documentation 🌍
839812----------------
840813
0 commit comments