{"action":"opened","issue":{"url":"https://api.github.com/repos/Vhoyon/Vramework/issues/5","repository_url":"https://api.github.com/repos/Vhoyon/Vramework","labels_url":"https://api.github.com/repos/Vhoyon/Vramework/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/Vhoyon/Vramework/issues/5/comments","events_url":"https://api.github.com/repos/Vhoyon/Vramework/issues/5/events","html_url":"https://github.com/Vhoyon/Vramework/issues/5","id":362715053,"node_id":"MDU6SXNzdWUzNjI3MTUwNTM=","number":5,"title":"Implement a way to handle pluralization in language lines","user":{"login":"V-ed","id":16652915,"node_id":"MDQ6VXNlcjE2NjUyOTE1","avatar_url":"https://avatars3.githubusercontent.com/u/16652915?v=4","gravatar_id":"","url":"https://api.github.com/users/V-ed","html_url":"https://github.com/V-ed","followers_url":"https://api.github.com/users/V-ed/followers","following_url":"https://api.github.com/users/V-ed/following{/other_user}","gists_url":"https://api.github.com/users/V-ed/gists{/gist_id}","starred_url":"https://api.github.com/users/V-ed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/V-ed/subscriptions","organizations_url":"https://api.github.com/users/V-ed/orgs","repos_url":"https://api.github.com/users/V-ed/repos","events_url":"https://api.github.com/users/V-ed/events{/privacy}","received_events_url":"https://api.github.com/users/V-ed/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-21T17:48:25Z","updated_at":"2018-09-21T17:48:25Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"@V-ed commented on [Thu Jun 21 2018](https://github.com/Vhoyon/Discord-Bot/issues/87)\n\nThis could be heavily inspired by Laravel's Localization utility (https://laravel.com/docs/5.6/localization#retrieving-translation-strings) :\r\n\r\n```\r\nAppleCount=[0] There are none|[1,19] There are some|[20,*] There are many\r\n```\r\n\r\nA new method to get those types of lines would be added to the [Translatable](https://github.com/Vhoyon/Discord-Bot/blob/dev/framework/vendor/interfaces/Translatable.java) and [Dictionary](https://github.com/Vhoyon/Discord-Bot/blob/dev/framework/vendor/objects/Dictionary.java) objects : `langAmount()`.\r\n\r\nThis `langAmount` method would take some parameters :\r\n```java\r\n/**\r\n@param key Key of the lang to map from the lang() method.\r\n@param amount Integer telling the amount of objects there is - used to determine which portion of the lang to pick from the list.\r\n@param replacements Variable amount of replacements to replace text in the line found.\r\n*/\r\nString langAmount(String key, int amount, String... replacements)\r\n```\r\n\r\nThis way, to further the example above, trying to access `AppleCount` would be like so :\r\n```java\r\nString appleText = langAmount(\"AppleCount\", list.size());\r\n```\r\n\r\nAnother example would be this string :\r\n```\r\nVariableCounter=[0] There is no variable here!|[1] There is only 1 variable here...|[2,20] There are {0} variables here!|[21,*] There is too many variables in here, the maximum accepted is 20!\r\n```\r\nAccessed this way :\r\n```java\r\nString variableCountText = langAmount(\"VariableCounter\", variables.size(), variable.size());\r\n```\r\nIn that example, if the number of variable is between 2 and 20, it will actually show the number of variables in the formatted text, and that in different languages if wanted!\r\n```java\r\nint size;\r\n\r\nsize = 4;\r\nString variableCountText = langAmount(\"VariableCounter\", size, size);\r\n// variableCountText = \"There are 4 variables here!\"\r\n\r\nsize = 1;\r\nString variableCountText = langAmount(\"VariableCounter\", size, size);\r\n// variableCountText = \"There is only 1 variable here...\"\r\n\r\nsize = 24;\r\nString variableCountText = langAmount(\"VariableCounter\", size, size);\r\n// variableCountText = \"There is too many variables in here, the maximum accepted is 20!\"\r\n```\r\n\r\nWe could throw a custom `NumberOutOfRangeException` (_that extends `IndexOutOfBoundsException`_) if the number is not between the range the line allowed :\r\n```java\r\nint size = -2;\r\nString variableCountText = langAmount(\"VariableCounter\", size, size);\r\n// throws NumberOutOfRangeException\r\n```\n\n---\n\n@V-ed commented on [Tue Jul 31 2018](https://github.com/Vhoyon/Discord-Bot/issues/87#issuecomment-409271498)\n\nI started thinking about how this will be implemented and came up with an object to handle lang lines :\r\nhttps://gist.github.com/V-ed/ffa57aec6bf646d2749a03a01c21d265\r\n\r\nThis code is **not** meant to be used in our Bot yet, but might be used as a template later on. This was just a proof of concept that such string could be handled by an object automatically.\r\n\r\nThis gist also doesn't include an idea I had while doing the code snippet : a LangAmountManager that would keep track of which range is used, which is available, handle different formats automatically, etc.\r\n\r\n**I'll say it again just in case : Please do not use this gist as-is, as it is not optimized, not entirely functionnal (works on a perfect scenario but as no error handling, etc) and repeats code.**\n\n"}}
{"actor":{"display_login":"V-ed"}}