Show the language of players on their user page

exp_legacy recorded each player's locale in PlayerData statistics
which nothing read. The lua side now sends one ipc event with the
player's locale when they join and when they change language, the
instance forwards it, and the controller stores it on the player
record.

The Scenario section of the user page shows the language by name with
a flag made from regional indicator symbols. Locales with a region use
it directly, the rest map to a country through a small table covering
Factorio's locale list. Arabic, Catalan, Basque, and Esperanto have no
single country and get no flag.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-10-14 22:10:31 +00:00
1 parent 6821d62c10
commit ebe7504c00
17 files changed
+155 -34

No files matched your search

+34
View File
@@ -134,6 +134,8 @@ export class PlayerRecord {
public id: string,
/** Shown to everyone when the player joins */
public joinMessage?: string,
/** The language of their game, such as "en" or "pt-BR" */
public locale?: string,
public updatedAtMs: number = 0,
public isDeleted: boolean = false,
) {}
@@ -141,6 +143,7 @@ export class PlayerRecord {
static jsonSchema = Type.Object({
id: Type.String(),
join_message: Type.Optional(Type.String()),
locale: Type.Optional(Type.String()),
updated_at_ms: Type.Optional(Type.Number()),
is_deleted: Type.Optional(Type.Boolean()),
});
@@ -150,6 +153,9 @@ export class PlayerRecord {
if (this.joinMessage) {
json.join_message = this.joinMessage;
}
if (this.locale) {
json.locale = this.locale;
}
if (this.updatedAtMs) {
json.updated_at_ms = this.updatedAtMs;
}
@@ -163,6 +169,7 @@ export class PlayerRecord {
return new this(
json.id,
json.join_message,
json.locale,
json.updated_at_ms ?? 0,
json.is_deleted ?? false,
);
@@ -242,3 +249,30 @@ export class JoinMessageSetRequest {
return new this(json.player_name, json.message);
}
}
/** The language a player's game uses, sent when they join and when they change it. */
export class PlayerLocaleEvent {
declare ["constructor"]: typeof PlayerLocaleEvent;
static plugin = "exp_scenario" as const;
static type = "event" as const;
static src = "instance" as const;
static dst = "controller" as const;
constructor(
public playerName: string,
public locale: string,
) {}
static jsonSchema = Type.Object({
player_name: Type.String(),
locale: Type.String(),
});
toJSON() {
return { player_name: this.playerName, locale: this.locale };
}
static fromJSON(json: Static<typeof this.jsonSchema>) {
return new this(json.player_name, json.locale);
}
}