Optionally show source context next to reference paths & line numbers #268
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added optional support for showing the source code context next to the source file path and line number.
This helps provide a bit more context for translators who don't have access to the source code.
To enable the feature, add the
/source
or-source
option to i18n.PostBuild.exe command line.We have private git repos which we do not share with our translators, but often some terse extracted nuggets can be clarified simply by looking at the original source line. So I added an option that includes the actual source after the source filename & line number.
When the option is enabled, it would turn an ambiguous message definition of
%0 Parameter
like this:into something a bit more clear like this:
Context like the above is often enough for a tech-savvy translator, (who knows our product domain and knows our software has a view which shows the parameter name of various statistics) to recognize the English text in context, and reason on their own that
%0 Parameter
is a substitution expression for various environmental monitoring parameters like "Accumulated Rain Fall Parameter", and a 'parameter' in the general computer-science context.It probably isn't safe to always the source context after the reference path and line number. There are plenty of "PO editor" implementations out there, and they might not expect it. It certainly works for the two I've tried (Poedit and Sisulizer), but who knows what else might fall over.
Changes:
PathNormalizer
class to eliminate hard-coded paths showing up in the generatedmessages.po
filesConsider this project folder structure:
Without path normalization, the following file would be generated:
That full path is not really needed, and just adds to the noise in the generated file.
With path normalization, the generated file contains relative path references to ProjectA:
The anchor path for normalization is the config file (web.config in this example).
If the path being normalized shares any common root with the anchor path (ie. they exist on the same drive), then a relative path will result. If the path has nothing in common with the anchor path, then the full absolute path is returned. There's nothing to normalize in that case.
ReferenceContext
class to replace the separatereferencePath
string andlineNumber
integer in the nugget extractor code.The
ReferenceContext
class also contains aContext
property from where the nugget was extracted. If the globalShowSourceContext
flag is true, then this context will be added to the comment line in the generated file.The
i18n.PostBuild.exe
tool will now exit with a zero exit code if successful. If anything goes wrong, it exits with a positive exit code. This helps build scripts detect failures when things go sideways.