-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Localization support for any prototypes #4335
base: master
Are you sure you want to change the base?
Localization support for any prototypes #4335
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The given example is bad because it uses ISerializationHooks which are obsolete.
The localized strings should just get resolved once after prototypes have been (re)loaded, which would also mean you could just get rid of the caching dictionary.
string? name = null; | ||
string? desc = null; | ||
|
||
foreach (var prototype in _prototype.EnumerateParents(kind, prototypeId, true)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't recursively iterate up through a prototypes parents, this is just the direct parent list
if (!_prototype.TryIndex(kind, prototypeId, out var prototype)) | ||
return new PrototypeLocData("", ""); | ||
|
||
var lproto = (ILocalizedPrototype)prototype; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try cast
[DataField("name")] public string? SetName { get; } | ||
|
||
[DataField("description")] public string? SetDesc { get; } | ||
|
||
[ViewVariables] public string Name { get; } | ||
|
||
[ViewVariables] public string Description { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be wrong, but I don't think the data-field attributes do anything on interfaces?
I'm also not sure about whether VV works on interfaces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, these should have documentation comments
I just noticed the review, I'll see what I can do, thanks |
{ | ||
// Concurrent dict so that multiple threads "reading" .Name won't cause a concurrent write issue | ||
// when the cache gets populated. | ||
private readonly ConcurrentDictionary<string, PrototypeLocData> _prototypeCache = new(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be per-prototype
NVM see my earlier comment, just remove it altogether.
if (args.ByType.ContainsKey(typeof(EntityPrototype))) | ||
FlushEntityCache(); | ||
|
||
FlushPrototypeCache(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should enumerate over kinds and only flush the cache for prototypes that actually changed.
Also FlushPrototypeCache() is broken, its just a copy paste of FlushEntityCache()
NVM see my earlier comment, just remove it altogether.
@ficcialfaint when |
This is probably too old to merge anymore. Close? |
… into localized-prototypes # Conflicts: # Robust.Shared/Localization/ILocalizationManager.cs # Robust.Shared/Localization/LocalizationManager.Entity.cs
About the PR
The PR adds ability to turn any prototype into
localized prototype
that supports localization in fluent file with custom prefix as entities do withent-
prefix.How does it work?
There is now a new
ILocalizedPrototype
interface. You simply implement it in your prototype and add:SetName
-- the default name you set in the prototype, in YAML filesSetDesc
-- same asSetName
but for descriptionsName
-- the localized nameDescription
-- the localized descriptionCustomLocalizationPrefix
- the prefix that will be used in.ftl
files. For example, entities useent-
prefix:ent-BaseItem = base item
Then you have to set
Name
's andDescription
's getters toILocalizationManager.GetPrototypeData<YourPrototype>(ID).Description
/.Name
.Here is a small example for a localized prototype:
Media