Replies: 6 comments 24 replies
-
Here´s a possible "workflow", at least how I imagine code-first-i18n to work, atm.
[CodeFirstLocalizable]
interface ILocalizables
{
///<summary>
/// Hello '<paramref name="world"/>'
///</summary>
/// <param name="world">the name of the world to be greeted</param>
/// <returns></returns>
LocalizedString Hello(string world);
}
partial class Localizables : ILocalizables
{
public LocalizedString Hello(string world) => ...;
}
|
Beta Was this translation helpful? Give feedback.
-
I'm still trying to wrap my head around your proposal here, so I don't have much to comment about it yet. However, I thought I'd point out a similar effort that I've worked on in the past: https://github.com/MarkPflug/Sylvan.BuildTools.Resources. It is a package that provides localization support very similar to what .resx files offer, but rather than using XML, it uses JSON (.resj) files. The project readme outlines a few of the advantages over resx, if you're interested. My package uses build-time code generation (an MSBuild task), rather than compile-time code gen (source generator) as your project uses. I don't see a huge advantage to one over the other. The one limitation I found with source generators was that it isn't (yet) possible to add embedded resources to the compilation. My project only came about as a proof-of-concept, for a larger project I was working on professionally, so I haven't really been adding much to it recently. Resx uses a combination of design-time (Visual Studio custom tool) for code generation and build-time (MSBuild task) for creating the embedded resources. I was trying to find a way to do something similar that didn't require Visual Studio, so other developers could use VSCode and still be able to manage the resj files. One idea from your project that I really like is the strongly-typed formatter method design. My project, much like RESX, only produces localized strings, so if a localized string is a format string, it is up to the consumer to apply the correct formatting, which wouldn't have any compile time checks. It looks like your project is mostly targeted at the new Anyway, just wanted to say hi. I'll be keeping an eye on your project's progress. Cheers, |
Beta Was this translation helpful? Give feedback.
-
Hi, I'm Ivan and I have done something similar to i18n is a pain for developers. Making it as effortless as possible is certainly a goal tooling should strive for. In my opinion the main problem is that the place where you call the translation function is not the place where your strings are stored (key-based translations). If you need to add a new string to the application, you need to come up with a new key, write the string into a dictionary-file and then call the translation function inside the code. If I understand everything correctly, you want to eliminate the step of requiring a developer to manually write something into the dictionary file. He does not need to leave the file where he wants to call the translation function. I like that approach as it eliminates a pain-point when dealing with i18n. I'm currently working on a draft of a concept to make i18n more accessible to web developers: https://github.com/pipeli18ne/RFC |
Beta Was this translation helpful? Give feedback.
-
Hey ya´ll. I recently made some huge steps making this happen, first MVP is about to land soon. See #88. |
Beta Was this translation helpful? Give feedback.
-
https://github.com/earloc/TypealizR/releases/tag/v0.9.2 just landed. |
Beta Was this translation helpful? Give feedback.
-
I introduce https://github.com/inlang/inlang. One of the apps lets translators manage translations directly on a git repo without the need for re-import/sync. There seems to be a general overlap in the goal of TypealizR and inlang: make i18n easier, especially for developers. |
Beta Was this translation helpful? Give feedback.
-
introduction
Inspired by the (at time of writing this) still ongoing discussion over at #70 (and partially #38) I´m currently starting to think about code-first-i18n - similar to what code-first-databases are offering to us.
I´ll try to sketch out the idea emerging in my mind.
When it comes to translating apps, the first thing a dev needs to do is place some simple string (
"Hello App"
) or templated-string ("Hello {0}"
) somewhere within the app.In .net-land this probably would be utilizing plain old
resx
-files (orresw
in UWP, etc.).There are other options, indeed, like OrchardCore.Localization for po-files (which I currently really need to explore more) or other offerings from - mostly paid - third parties (like poeditor or localizely, just to name a few).
As I understand currently, all those offerings mostly are based on the fact that there IS already some sort of tech-stack native localization file (in .net-land some
resx
- or maybe anxliff
-file), which is used as the point of interchange.Getting to those files currently isn´t very intuitive or "developer-friendly", at least from my personal point-of-view.
So, what am I proposing?
code-first i18n
From a developer´s point-of-view, all I really want is some sort if
Interface
I can inject and leverage existing IDE refactorings to introduce newlocalizables
.Why isn´t introducing a new
localizable
as easy as writing a new method (inlcuding parameters, if needed) and hittingCTRL+.
and selectingGenerate method
:nice idea, but how does this help?
Exactly, this doesn´t really help now, as there´s nowhere some usable implementation around.
This is where
TypealizR
could kick in. By marking theInterface
with something like[Typealize]
, asource-generator
could emit a discrete implementation, as well as some sort of actual default exchange-file for storing actuallocalizables
. This could be an ordinaryresx
-file OR axliff
/po
, whatever. What the actual implementation really does, is currently not specified. Could be looking up from some file, or just honoring the requestedCulture
and deliver a static string - doesn´t really matter.Inspired by what MAT does, this could then be used to generate even more files intended for interchange with translators or tools like poeditor / localizely / whatever.
There´d need to be - of course - some mechanism to re-import such an exchange-file, to support workflows involving external tools / translation-providers. But this looks kind-of solvable, atm. Even if that would involve taking
translatables
back and incorporating those into the static strings, which might be returned by generated code.Any opinions?
Beta Was this translation helpful? Give feedback.
All reactions