Comments (5)
PHP/XHTML parser expects all XML nodes to be balanced, since it is a validating parser. This parser is used to localize text nodes in mostly static PHP (or pure HTML/XHTML) pages. You seem to try to localize a GraphQL library file (which by common convention has an opening <?php
clause but no ending ?>
one, so it is not balanced). But even putting this fact aside, this file doesn't seem to have any localizable content, so there's no reason to pass it through Serge at all.
If your question is how to exclude some files or directories from being processed by Serge, then look at source_exclude job parameter.
from serge.
Well, I'm trying to process php-files which contain source-code for our application, which has translationable strings. It will indeed never have closing tags so it will not be unbalanced.
Is there a way to use xgettext since that is able to parse the php-files?
from serge.
Serge was designed around the notion of localizing resource files, and what it does by default is generates localized copies of such resources. Since you have strings mixed with source code, and you definitely don't want that source code to be duplicated, you can address this in multiple ways:
Option A: manually extract localizable strings from sources into separate files. I recommend storing strings as PHP files with native associative arrays so that you don't have to write much code to use these files. This format is optimal for runtime, and you can use parse_hash parser for such files.
Option B: use xgettext
or your own tool to automatically extract strings from the source code into your resource file. With xgettext the limitation will be that the resource files will be created in .po (.pot) format, and you will need to use PHP-s gettext library and other tools to compile resources into .mo format and then use them. The generated .pot files can be then processed by Serge using parse_pot parser.
Option C: write a custom parser for Serge to extract Gettext-like strings from your source files; this parser, instead of creating localized copies of source files, would generate one resource file per language (basically, dump data from Serge database in however format you like). This option is more involving (needs writing some custom code for Serge) but potentially allows you to do everything automatically on one step, without using external tools like xgettext.
My personal preference is Option A, since it gives you the full control over the result and allows you to disambiguate strings properly (because the same string in multiple places ideally should appear multiple times in resource files under different keys).
from serge.
Thanks for the elaborate answer. I found it very helpful.
Before you answered, I managed to get option B working, but I'll take option A in consideration. Option C looks a bit daunting.
Any chance this information can be integrated in the documentation on serge.io? I found it a bit lacking for first time users. What I mean by this that it's not that easy to set up serge because there isn't a complete tutorial but only pages with parts of the solution.
from serge.
Thanks for suggestions, @Zombaya! Serge documentation definitely will be improved over time. Your questions — and questions from other users — help me understand how other people intend to use Serge, and what topics need to be covered. And one of the motivations for me to provide such elaborate answers is that I will be able to reuse them later in the documentation.
from serge.
Related Issues (20)
- parse_php_xhtml: add an ability to fine-tune the list of tags processed by default
- Serge always prints debug output on CI. HOT 1
- Qt Text Id based (ts files) HOT 5
- Localized file generation failed HOT 5
- Typo bug: DROP index items_file_id_string_id after CREATE HOT 1
- Add support for computed properties in parse_js parser
- Optimizations prevent reusing translations on existing unmodified files
- Cannot use env variable on boolean property
- Serge surprisingly cuts file name. HOT 3
- transliterate option of test_language plugin should not modify printf() parameter fields
- [Question] Are there any examples (e.g. GitLab CI)?
- Support multiple source files in single XLIFF file HOT 1
- Each <trans-unit> sets "approved=yes" for untranslated strings HOT 3
- parse nginx.conf bug,include not support wildcard HOT 1
- While put the mouse on (Notebooks section) we are unable to place mouse directly on scroll bar, please increase the mouse scroll width like how the size it as page right hand side up and down scroll bar size.
- Parse MD file
- run_command for jobs with several destination_languages dont change %OUTFILE% variable HOT 1
- export_to_ttx is not including the translated text
- Docs no longer easily accessible HOT 1
- Ownership transfer request HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serge.