--- title: i18n --- # Service: `i18n` ## Types ### `type Options` ```go type Options 0 *ast.StructType { 1 . Struct: - 2 . Fields: *ast.FieldList { 3 . . Opening: - 4 . . List: nil 5 . . Closing: - 6 . } 7 . Incomplete: false 8 } ``` Options holds configuration for the i18n service. ### `type Service` ```go type Service 0 *ast.StructType { 1 . Struct: - 2 . Fields: *ast.FieldList { 3 . . Opening: - 4 . . List: []*ast.Field (len = 4) { 5 . . . 0: *ast.Field { 6 . . . . Doc: nil 7 . . . . Names: nil 8 . . . . Type: *ast.StarExpr { 9 . . . . . Star: - 10 . . . . . X: *ast.IndexExpr { 11 . . . . . . X: *ast.SelectorExpr { 12 . . . . . . . X: *ast.Ident { 13 . . . . . . . . NamePos: - 14 . . . . . . . . Name: "core" 15 . . . . . . . . Obj: nil 16 . . . . . . . } 17 . . . . . . . Sel: *ast.Ident { 18 . . . . . . . . NamePos: - 19 . . . . . . . . Name: "Runtime" 20 . . . . . . . . Obj: nil 21 . . . . . . . } 22 . . . . . . } 23 . . . . . . Lbrack: - 24 . . . . . . Index: *ast.Ident { 25 . . . . . . . NamePos: - 26 . . . . . . . Name: "Options" 27 . . . . . . . Obj: *ast.Object { 28 . . . . . . . . Kind: type 29 . . . . . . . . Name: "Options" 30 . . . . . . . . Decl: *ast.TypeSpec { 31 . . . . . . . . . Doc: nil 32 . . . . . . . . . Name: *ast.Ident { 33 . . . . . . . . . . NamePos: - 34 . . . . . . . . . . Name: "Options" 35 . . . . . . . . . . Obj: *(obj @ 27) 36 . . . . . . . . . } 37 . . . . . . . . . TypeParams: nil 38 . . . . . . . . . Assign: - 39 . . . . . . . . . Type: *ast.StructType { 40 . . . . . . . . . . Struct: - 41 . . . . . . . . . . Fields: *ast.FieldList { 42 . . . . . . . . . . . Opening: - 43 . . . . . . . . . . . List: nil 44 . . . . . . . . . . . Closing: - 45 . . . . . . . . . . } 46 . . . . . . . . . . Incomplete: false 47 . . . . . . . . . } 48 . . . . . . . . . Comment: nil 49 . . . . . . . . } 50 . . . . . . . . Data: nil 51 . . . . . . . . Type: nil 52 . . . . . . . } 53 . . . . . . } 54 . . . . . . Rbrack: - 55 . . . . . } 56 . . . . } 57 . . . . Tag: nil 58 . . . . Comment: nil 59 . . . } 60 . . . 1: *ast.Field { 61 . . . . Doc: nil 62 . . . . Names: []*ast.Ident (len = 1) { 63 . . . . . 0: *ast.Ident { 64 . . . . . . NamePos: - 65 . . . . . . Name: "bundle" 66 . . . . . . Obj: *ast.Object { 67 . . . . . . . Kind: var 68 . . . . . . . Name: "bundle" 69 . . . . . . . Decl: *(obj @ 60) 70 . . . . . . . Data: nil 71 . . . . . . . Type: nil 72 . . . . . . } 73 . . . . . } 74 . . . . } 75 . . . . Type: *ast.StarExpr { 76 . . . . . Star: - 77 . . . . . X: *ast.SelectorExpr { 78 . . . . . . X: *ast.Ident { 79 . . . . . . . NamePos: - 80 . . . . . . . Name: "i18n" 81 . . . . . . . Obj: nil 82 . . . . . . } 83 . . . . . . Sel: *ast.Ident { 84 . . . . . . . NamePos: - 85 . . . . . . . Name: "Bundle" 86 . . . . . . . Obj: nil 87 . . . . . . } 88 . . . . . } 89 . . . . } 90 . . . . Tag: nil 91 . . . . Comment: nil 92 . . . } 93 . . . 2: *ast.Field { 94 . . . . Doc: nil 95 . . . . Names: []*ast.Ident (len = 1) { 96 . . . . . 0: *ast.Ident { 97 . . . . . . NamePos: - 98 . . . . . . Name: "localizer" 99 . . . . . . Obj: *ast.Object { 100 . . . . . . . Kind: var 101 . . . . . . . Name: "localizer" 102 . . . . . . . Decl: *(obj @ 93) 103 . . . . . . . Data: nil 104 . . . . . . . Type: nil 105 . . . . . . } 106 . . . . . } 107 . . . . } 108 . . . . Type: *ast.StarExpr { 109 . . . . . Star: - 110 . . . . . X: *ast.SelectorExpr { 111 . . . . . . X: *ast.Ident { 112 . . . . . . . NamePos: - 113 . . . . . . . Name: "i18n" 114 . . . . . . . Obj: nil 115 . . . . . . } 116 . . . . . . Sel: *ast.Ident { 117 . . . . . . . NamePos: - 118 . . . . . . . Name: "Localizer" 119 . . . . . . . Obj: nil 120 . . . . . . } 121 . . . . . } 122 . . . . } 123 . . . . Tag: nil 124 . . . . Comment: nil 125 . . . } 126 . . . 3: *ast.Field { 127 . . . . Doc: nil 128 . . . . Names: []*ast.Ident (len = 1) { 129 . . . . . 0: *ast.Ident { 130 . . . . . . NamePos: - 131 . . . . . . Name: "availableLangs" 132 . . . . . . Obj: *ast.Object { 133 . . . . . . . Kind: var 134 . . . . . . . Name: "availableLangs" 135 . . . . . . . Decl: *(obj @ 126) 136 . . . . . . . Data: nil 137 . . . . . . . Type: nil 138 . . . . . . } 139 . . . . . } 140 . . . . } 141 . . . . Type: *ast.ArrayType { 142 . . . . . Lbrack: - 143 . . . . . Len: nil 144 . . . . . Elt: *ast.SelectorExpr { 145 . . . . . . X: *ast.Ident { 146 . . . . . . . NamePos: - 147 . . . . . . . Name: "language" 148 . . . . . . . Obj: nil 149 . . . . . . } 150 . . . . . . Sel: *ast.Ident { 151 . . . . . . . NamePos: - 152 . . . . . . . Name: "Tag" 153 . . . . . . . Obj: nil 154 . . . . . . } 155 . . . . . } 156 . . . . } 157 . . . . Tag: nil 158 . . . . Comment: nil 159 . . . } 160 . . } 161 . . Closing: - 162 . } 163 . Incomplete: false 164 } ``` Service provides internationalization and localization. #### Methods - `HandleIPCEvents(c 0 *ast.StarExpr { 1 . Star: - 2 . X: *ast.SelectorExpr { 3 . . X: *ast.Ident { 4 . . . NamePos: - 5 . . . Name: "core" 6 . . . Obj: nil 7 . . } 8 . . Sel: *ast.Ident { 9 . . . NamePos: - 10 . . . Name: "Core" 11 . . . Obj: nil 12 . . } 13 . } 14 } , msg 0 *ast.SelectorExpr { 1 . X: *ast.Ident { 2 . . NamePos: - 3 . . Name: "core" 4 . . Obj: nil 5 . } 6 . Sel: *ast.Ident { 7 . . NamePos: - 8 . . Name: "Message" 9 . . Obj: nil 10 . } 11 } ) 0 *ast.Ident { 1 . NamePos: - 2 . Name: "error" 3 . Obj: nil 4 } `: HandleIPCEvents processes IPC messages, including injecting dependencies on startup. - `ServiceStartup( 0 *ast.SelectorExpr { 1 . X: *ast.Ident { 2 . . NamePos: - 3 . . Name: "context" 4 . . Obj: nil 5 . } 6 . Sel: *ast.Ident { 7 . . NamePos: - 8 . . Name: "Context" 9 . . Obj: nil 10 . } 11 } , 0 *ast.SelectorExpr { 1 . X: *ast.Ident { 2 . . NamePos: - 3 . . Name: "application" 4 . . Obj: nil 5 . } 6 . Sel: *ast.Ident { 7 . . NamePos: - 8 . . Name: "ServiceOptions" 9 . . Obj: nil 10 . } 11 } ) 0 *ast.Ident { 1 . NamePos: - 2 . Name: "error" 3 . Obj: nil 4 } `: ServiceStartup is called when the app starts, after dependencies are injected. - `SetLanguage(lang 0 *ast.Ident { 1 . NamePos: - 2 . Name: "string" 3 . Obj: nil 4 } ) 0 *ast.Ident { 1 . NamePos: - 2 . Name: "error" 3 . Obj: nil 4 } `: - `Translate(messageID 0 *ast.Ident { 1 . NamePos: - 2 . Name: "string" 3 . Obj: nil 4 } ) 0 *ast.Ident { 1 . NamePos: - 2 . Name: "string" 3 . Obj: nil 4 } `: ## Functions - `Register(c 0 *ast.StarExpr { 1 . Star: - 2 . X: *ast.SelectorExpr { 3 . . X: *ast.Ident { 4 . . . NamePos: - 5 . . . Name: "core" 6 . . . Obj: nil 7 . . } 8 . . Sel: *ast.Ident { 9 . . . NamePos: - 10 . . . Name: "Core" 11 . . . Obj: nil 12 . . } 13 . } 14 } ) 0 *ast.Ident { 1 . NamePos: - 2 . Name: "any" 3 . Obj: nil 4 } , 0 *ast.Ident { 1 . NamePos: - 2 . Name: "error" 3 . Obj: nil 4 } `: Register is the constructor for dynamic dependency injection (used with core.WithService). It creates a Service instance and initializes its core.Runtime field. Dependencies are injected during ServiceStartup. - `detectLanguage(supported 0 *ast.ArrayType { 1 . Lbrack: - 2 . Len: nil 3 . Elt: *ast.SelectorExpr { 4 . . X: *ast.Ident { 5 . . . NamePos: - 6 . . . Name: "language" 7 . . . Obj: nil 8 . . } 9 . . Sel: *ast.Ident { 10 . . . NamePos: - 11 . . . Name: "Tag" 12 . . . Obj: nil 13 . . } 14 . } 15 } ) 0 *ast.Ident { 1 . NamePos: - 2 . Name: "string" 3 . Obj: nil 4 } , 0 *ast.Ident { 1 . NamePos: - 2 . Name: "error" 3 . Obj: nil 4 } `: - `getAvailableLanguages() 0 *ast.ArrayType { 1 . Lbrack: - 2 . Len: nil 3 . Elt: *ast.SelectorExpr { 4 . . X: *ast.Ident { 5 . . . NamePos: - 6 . . . Name: "language" 7 . . . Obj: nil 8 . . } 9 . . Sel: *ast.Ident { 10 . . . NamePos: - 11 . . . Name: "Tag" 12 . . . Obj: nil 13 . . } 14 . } 15 } , 0 *ast.Ident { 1 . NamePos: - 2 . Name: "error" 3 . Obj: nil 4 } `: