namespace SharedTools; /// /// Computes the hash which turns a text of T() or TB() into its I18N key. /// /// /// The I18N collector and the app both use it: the collector for the text it reads from the source, the app for the /// string it gets at runtime. A multi-line text holds the line endings of the checkout it was compiled from, so the /// hash makes them equal first; otherwise, a build from a Windows checkout would find no translation for such a /// text. Texts without line breaks keep the hash they always had. /// public static class I18NKeyHash { /// /// Computes the hash of a text. /// /// The text, as T() or TB() gets it. /// The 32-bit FNV-1a hash of the text with LF line endings. public static uint Of(string text) => NormalizeLineEndings(text).ToFNV32(); /// /// Turns CRLF and CR line endings into LF. /// /// The text. /// The text with LF line endings, or the text itself when it holds no CR. public static string NormalizeLineEndings(string text) => text.Contains('\r') ? text.Replace("\r\n", "\n").Replace('\r', '\n') : text; }